cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Solve Block Iteration

TJ_10739611
4-Participant

Solve Block Iteration

Hi all,

 

I am aware that this topic has been covered many times before, but I am a bit puzzled on how to achieve an iterated solve block in Mathcad Prime 4.0. I cannot attach my worksheet, unfortunately, but I will attach an image to illustrate what I am trying to do below.

 

TJ_10739611_0-1690197959664.png

 

 

I have one equation in terms of x, and one in terms of i. I want to find all the (x,i) points where the values of these functions are equal. The way I thought to do it was to somehow nest a solve block in a for loop. 

 

I've seen previous posts that use the "Find" function, but I guess in prime, I can only use the "find" function inside a solve block. 

 

The problem is that I'm looking for pretty good resolution in my data points. This is why in the attached image, i is a range variable going from 0 - 1200 mA. My end goal is to get a matrix of x values that correspond to those i values.

 

I truly appreciate the help, and I hope I'm not beating a dead horse too much!

 

Thanks,

Tyler

 

1 ACCEPTED SOLUTION

Accepted Solutions

"find" has to be used in a solve block, yes. An alternative is using the root() function.

Here is what I guess is a solution using a solve block with find.

You could have provided a simple demo sheet with dummy functions so we would have also seen what the units of the functions and of x are supposed to be..

I defined some senseless functions here (the names of the formal arguments do not matter, I used x and y)

Werner_E_0-1690210156424.png

and the set up a solve block, turned into a function of i (again, the name could be anything)

Werner_E_2-1690210286325.png

As you can see in the pic above you now have a function get_x() which returns the x-value for every i-value you provide.

Use it as any other function you know.

You can make a plot of x over i

Werner_E_3-1690210434109.png

Note that iA is a range variable only used for plotting.

You have to distinguish between vectors and ranges. Ranges should only be used for

1) plotting (as above)

2) to index the elements of vectors or matrices

3) in a program when you use a for-loop

Never use ranges to create a table of values or the like!

ttokoro just had shown an undocumented trick to turn a range into a vector by following the assignment with an evaluation (the = at the end).

You may also create a vector in a more "legal" way, though.

Lets say we want a vector with 13 equally spaced values from 0mA to 1200mA. So the first step is to define a range i:=0..12 which then is used to index the vector ii we create:

Werner_E_9-1690211495607.png

Note that in the definition if ii the index i is a vector/matrix index, not a literal index.

 

Now you can feed this vector as argument  in the function get_x() but you have to use the vectorization operator (the arrow over the expression).

You may assign this to another variable or just display it side by side to ii so you see which i results in which x.

Werner_E_5-1690210911749.png

You may also use augment to create a matrix, but because the two columns use different dimensions/units, the units are displayed IN the matrix and unfortunately cannot be changed to something else - its the standard units only, so you can't

show mA

Werner_E_6-1690211061026.png

If a table is what you are looking for you might consider creating a table without unit by dividing each column by the unit you'd like the values to be in (just for fun I used lb for mass):

Werner_E_7-1690211393859.png

Feel free to add a descriptive header

Werner_E_8-1690211434528.png

 

Of course you can create a vector ii with more values if needed, like the 1201 values you had initially set up

Werner_E_11-1690211617306.png

BTW, the aforementioned undocumented trick

Werner_E_1-1690212108871.png

would create the very same vector ii.

 

 

 

 

View solution in original post

4 REPLIES 4
ttokoro
20-Turquoise
(To:TJ_10739611)

Make only 13 answers instead of 1201 answers.

image.png

TJ_10739611
4-Participant
(To:ttokoro)

I guess 1201 was a bit overkill, haha. 

Thank you so much!!

 

All the best

"find" has to be used in a solve block, yes. An alternative is using the root() function.

Here is what I guess is a solution using a solve block with find.

You could have provided a simple demo sheet with dummy functions so we would have also seen what the units of the functions and of x are supposed to be..

I defined some senseless functions here (the names of the formal arguments do not matter, I used x and y)

Werner_E_0-1690210156424.png

and the set up a solve block, turned into a function of i (again, the name could be anything)

Werner_E_2-1690210286325.png

As you can see in the pic above you now have a function get_x() which returns the x-value for every i-value you provide.

Use it as any other function you know.

You can make a plot of x over i

Werner_E_3-1690210434109.png

Note that iA is a range variable only used for plotting.

You have to distinguish between vectors and ranges. Ranges should only be used for

1) plotting (as above)

2) to index the elements of vectors or matrices

3) in a program when you use a for-loop

Never use ranges to create a table of values or the like!

ttokoro just had shown an undocumented trick to turn a range into a vector by following the assignment with an evaluation (the = at the end).

You may also create a vector in a more "legal" way, though.

Lets say we want a vector with 13 equally spaced values from 0mA to 1200mA. So the first step is to define a range i:=0..12 which then is used to index the vector ii we create:

Werner_E_9-1690211495607.png

Note that in the definition if ii the index i is a vector/matrix index, not a literal index.

 

Now you can feed this vector as argument  in the function get_x() but you have to use the vectorization operator (the arrow over the expression).

You may assign this to another variable or just display it side by side to ii so you see which i results in which x.

Werner_E_5-1690210911749.png

You may also use augment to create a matrix, but because the two columns use different dimensions/units, the units are displayed IN the matrix and unfortunately cannot be changed to something else - its the standard units only, so you can't

show mA

Werner_E_6-1690211061026.png

If a table is what you are looking for you might consider creating a table without unit by dividing each column by the unit you'd like the values to be in (just for fun I used lb for mass):

Werner_E_7-1690211393859.png

Feel free to add a descriptive header

Werner_E_8-1690211434528.png

 

Of course you can create a vector ii with more values if needed, like the 1201 values you had initially set up

Werner_E_11-1690211617306.png

BTW, the aforementioned undocumented trick

Werner_E_1-1690212108871.png

would create the very same vector ii.

 

 

 

 

TJ_10739611
4-Participant
(To:Werner_E)

Thank you for such a descriptive and helpful response.

I really appreciate you taking all the time to help me out!!

 

All the best

Top Tags