11 Replies Latest reply: Jan 7, 2014 10:43 AM by WE

# Possible to create iterative solve blocks?

In the attached MathCAD 14 worksheet I am attempting to solve for the embedment length for multiple sets of variables ( concrete dimensions a,b,ma,mb) using the Given command/block. Is it possible to pass multiple groups of variables in these three equations and solve for the single variable E using the Given block?

For each set of variables only one equation is solvable for E while the other two will not be solveable. The solvable equation changes as the dimensions changes. If the equation is not solvable, is it possible to for MathCAD to return a zero or unsolveable response instead of turning red?

• ###### Re: Possible to create iterative solve blocks?

Not sure what kind of iteration you are talking about in the subject.

But if you get riod of the range variable and the elementwise (subscribted/indexed) notation using it, make E a 3x1 vector and, again, use vectorize, you get a solution.

Not sure about what you mean with only one equ would give a solution?

Concerning error catching you could turn the solve block into a parameterized function (whatever the input parameters would be) and create a new function using the "on error" statement to return NaN if the solve block function fails. See attached

But in your case it failed always because of kind bad syntax.

• ###### Re: Possible to create iterative solve blocks?

If you make the solve blocks as parameterized functions you can calculate the 3 results.

if some of them don't converge to a solution there was a function "ReDefine" posted on this forum which takes a text string parameter.

if there is a variable of that name it returns the value, if not it returns "Undefined" & this can be used in subsequent calculations.

Hope this is what you want

regards

Andy

• ###### Re: Possible to create iterative solve blocks?

Thank you Werner; the vectorize function and the error check function are very useful. This worksheet will ultimately be used for the anchorage for a large number of columns, some of which will make allow the different Ac equations to be solvable for E and some will not be solvable for E based on the input parameters.

Is it possible for the solution of the f(E) function to show the solution E value for instances when the equation is solvable and NaN for instances when it is not? For example, in the attached worksheet, all three areas, 130, 140, and 150 in^2, will create a solution for the exterior column equation but only 140 and 150 in^2 will create a solution for the interior column. Is it possible for the g(gs) function to provide a 3 position vector with NaN in the first position and the solution E values in the second and third position instead of just providing a NaN for the entire solution?

Andy, I’ve never seen this redefine function before, thank you very much. I’m going to figure out how this page works, it looks like it may provide the functionality I’m after.

EDIT: The e1, e2, e3 functions work well when the parameters solve all three equations, thanks! What exactly should go into the ReDefine function to make the esub1, esub2, & esub3 work when the parameters don't solve the Ac equations?

• ###### Re: Possible to create iterative solve blocks?

Daniel Sochor wrote:

Is it possible for the solution of the f(E) function to show the solution E value for instances when the equation is solvable and NaN for instances when it is not? ...

Like so?

Alan

• ###### Re: Possible to create iterative solve blocks?

That is what I was trying to do, thank you Alan!

• ###### Re: Possible to create iterative solve blocks?

With Alan's approach we can go back to let E, a, b, etc. be single scalar values and the equation in the solve block would not have to ve vectorized as its working on scalars only.

If it is necessary to provide different values of a, b, etc. for the different values of A.c, you could make them additional paremeters - see at the end of the attached file.

• ###### Re: Possible to create iterative solve blocks?

Thank you Werner for including the eval function. As can be seen in the first attachment, the prior mentioned vectorized error function was producing erroneous results.

Is it possible to force the eval command to accept 7 functions so that 3rd corner equation can be used?

• ###### Re: Possible to create iterative solve blocks?

As can be seen in the first attachment, the prior mentioned vectorized error function was producing erroneous results.

?? Do you mean because the first value differs from the others? This is because your k-loop runs from 1 to last(E) and not from 0 to last(E) as it should. Unless changed Mathcad defaults to begin indexing with 0, not with 1.

The solve block finds no solution, as the way you did it can not work. In the solve block function A.c and E are scalars, but a and b are still vectors.

For individual error checking you have to change the solve block to work with scalars only. See attached

• ###### Re: Possible to create iterative solve blocks?

Is it possible to force the eval command to accept 7 functions so that 3rd corner equation can be used?

Sure, just add m.b as a parameter to all functions - see attached.

Find at the end of the file a modified eval-function which takes scalars and vectors of different length as parameter - for whatever it may be worth.

• ###### Re: Possible to create iterative solve blocks?

Is it possible to modify the function in yellow to not consider or output complex results?

• ###### Re: Possible to create iterative solve blocks?

If you want to replace complex results by NaN's you may use

To get rid of the Nan's you may use the function "filterNaN()", but you would have to take care of the situations when the vector contains no NaN or only NaN's as the function will fail in those cases.