Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Iterate a solution to ASME design code in mathcad (whole workbook while loop possible?)

Status
Not open for further replies.

nick262b

Mechanical
Apr 17, 2013
25
0
0
GB
Hi everyone,

I have a working version of some ASME design code I have programmed into mathcad but am having trouble trying to figure out if I can use the code to iterate a solution.

There is a variable lets say X that is defined very early on in the code as a user input/initial value and is in this case the only independent variable.
For a given X all other values are calculated based on user inputs and the programmed formulae and it spits out an answer of pass/fail and values etc.

I want the whole sheet to essentially run as a while loop and increment X until the failure criteria are reached so that I can find the maximum values. I understand how to programme small while loops in mathcad but the code calculations are pages long and contain many If statements and huge equations with multiple returns and so this would get messy based on my current way of doing things (using addline command on a single variable). Is there a way I can achieve what I am wanting in mathcad?

In C++ for example each part of the code calculation would be a function and the main programme would simply call these in turn whilst running as a while loop incrementing the function argument X until the specified fail criteria.
before you suggest Excel, I have got this working easily in Excel but need the visual display properties of mathcad to present the work in an easily checkable format for when independent verifiers review the work. Also It would be nice to learn this capability in mathcad if it is possible.

Would one way be redefining all my equations as a function of X and then going from there? is there an easy way of doing this?

Any help that anyone can lend would be much appreciated.

Kind Regards,

Nick

 
Replies continue below

Recommended for you

The question is two month old and I am not sure if its still vacant, but for whatever its worth -
Would one way be redefining all my equations as a function of X and then going from there? is there an easy way of doing this?
Yes, and if you are not willing to rewrite larger parts of your sheet and turning calculations into functions this sure would be the way to do.
Instead of
Code:
X:=5
varable1:=5*X+4
variable2:=4/X +1/variable1
pass:="OK" if 2*variable2>6
      "FAIL" otherwise

you would write
Code:
var1(X):=5*X+4
var2(X):4/X +1/var1(X)
pass(X):="OK" if 2*var2(X)>6
         "FAIL" otherwise

and use
Code:
pass(X)
in your loop.
Of course, if, for example you don't need variable1/2 otherwise, you may consider merging some calculations into one program.
Unfortunately you can't use Mathcad's replace as the paranthesis (x) would be taken literal (like you had inserted them using Ctrl-Shift-K) and not as parameter.

 
Status
Not open for further replies.
Back
Top