×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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

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

The question is two month old and I am not sure if its still vacant, but for whatever its worth -

Quote:

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close