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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Mathcad 15 - Return a Value from a Solve Block if a Solution is Not Found

coberg
6-Contributor

Mathcad 15 - Return a Value from a Solve Block if a Solution is Not Found

I am working on a calculation sheet to design a bridge deck overhang.  The last check I need to do is to calculate the cutoff length of the supplemental bars that are used.  In order to do this, you need to solve/find the location where the applied moments become less than the moment resistance of the overhang without the supplemental bars. The only way I can think to achieve this is to use a solve block, however, this becomes a problem if/when the applied moments are less than moment resistance at the cutoff location.  See the images below.

coberg_0-1626959681410.png

For this example the variable Mr_co is the moment resistance at the cut-off location.  I have set up functions to calculate the ultimate strength moments for 2 different cases. As you can see by the graph, the ultimate strength moment for the one case does not quite reach the cut-off moment resistance.  I would like to set up the solve block so that if/when this happens, the return is 0, but I am not sure if this is possible because when the solve block cannot find a solution, it returns a "variable is undefined" error.

 

coberg_1-1626960077725.png

 

I have tried putting this in an if statement block, but the issues seems to be that the return of the Find function when it cannot find a solution.  Has anyone else run into this issue and found a solution around it?  I have also tried using the 'on error' operator and that does not work either.

 

Any help would be much appreciated!  Thank you! 

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:coberg)

Unfortunately "on error" does not work directly with "Find", but as a workaround you can turn the solve block into a function with a dummy argument and then you can use this function in an "on error" statement:

Werner_E_2-1627431126950.png

 

Instead of the "dummy" argument you may use x.guess2 as function argument so you don't have to define the guess value in front of the solve block and can call it trying different guesses.

View solution in original post

7 REPLIES 7
LucMeekes
23-Emerald III
(To:coberg)

Can you attach your worksheet, or else (even better) a worksheet that specifically shows the problem.

 

Success!
Luc

coberg
6-Contributor
(To:LucMeekes)

Attached is the file.  The 'Find' function is at the very end of the worksheet where I compute the theoretical cut-off location, page 52.  I have tried using a programming block with 'if' statements as well as the 'on error' function and the issue seems to be that the return of the 'Find' function is undefined.  

LucMeekes
23-Emerald III
(To:coberg)

Yep, the 'on error' cannot be used with a Find, probably because you cannot use Find in a program, and 'on error' is a programming construct.

I've been trying to define a function IsUndefined(var) that should check if var is undefined, in the past, and recently after I read your post. So far no luck. The problem with 'undefined' is that the variable is numerically undefined and this is caught by Mathcad at the calling of any use of an undefined variable. It only survives symbolic evaluation. But the problem with symbolic evaluation is that only certain IF statements work as desired.

 

Seems like you have to find other ways to determine (conditions where) Find will not find what you need, and test for those.

 

Success!
Luc

KM_9995988
2-Explorer
(To:coberg)


@Upsers wrote:

I am working on a calculation sheet to design a bridge deck overhang.  The last check I need to do is to calculate the cutoff length of the supplemental bars that are used.  In order to do this, you need to solve/find the location where the applied moments become less than the moment resistance of the overhang without the supplemental bars. The only way I can think to achieve this is to use a solve block, however, this becomes a problem if/when the applied moments are less than moment resistance at the cutoff location.  See the images below.

coberg_0-1626959681410.png

For this example the variable Mr_co is the moment resistance at the cut-off location.  I have set up functions to calculate the ultimate strength moments for 2 different cases. As you can see by the graph, the ultimate strength moment for the one case does not quite reach the cut-off moment resistance.  I would like to set up the solve block so that if/when this happens, the return is 0, but I am not sure if this is possible because when the solve block cannot find a solution, it returns a "variable is undefined" error.

 

coberg_1-1626960077725.png

 

I have tried putting this in an if statement block, but the issues seems to be that the return of the Find function when it cannot find a solution.  Has anyone else run into this issue and found a solution around it?  I have also tried using the 'on error' operator and that does not work either.

 

Any help would be much appreciated!  Thank you! 


Just delete the equal after Find. Mathcad 15 don't like vectors with different units.

 

coberg
6-Contributor
(To:KM_9995988)

Deleting the equal after Find does not work because the definition of the variable is predicated on the 'Find' function.  Since the the solver cannot find a solution, the return of the 'Find' function is undefined, which is the ultimate problem.

Werner_E
25-Diamond I
(To:coberg)

Unfortunately "on error" does not work directly with "Find", but as a workaround you can turn the solve block into a function with a dummy argument and then you can use this function in an "on error" statement:

Werner_E_2-1627431126950.png

 

Instead of the "dummy" argument you may use x.guess2 as function argument so you don't have to define the guess value in front of the solve block and can call it trying different guesses.

Werner_E
25-Diamond I
(To:Werner_E)

Instead of using a solve block you may consider using the "root" function, which can be used with "on error".

Either the variant where you provide a guess value

Werner_E_3-1627432078657.png

or the one where you provide a range

Werner_E_5-1627432174276.png

 

 

Announcements

Top Tags