Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X
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.
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
Solved! Go to Solution.
"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)
and the set up a solve block, turned into a function of i (again, the name could be anything)
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
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:
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.
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
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):
Feel free to add a descriptive header
Of course you can create a vector ii with more values if needed, like the 1201 values you had initially set up
BTW, the aforementioned undocumented trick
would create the very same vector ii.
Make only 13 answers instead of 1201 answers.
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)
and the set up a solve block, turned into a function of i (again, the name could be anything)
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
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:
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.
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
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):
Feel free to add a descriptive header
Of course you can create a vector ii with more values if needed, like the 1201 values you had initially set up
BTW, the aforementioned undocumented trick
would create the very same vector ii.
Thank you for such a descriptive and helpful response.
I really appreciate you taking all the time to help me out!!
All the best