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

Writing Pseudocode in MATHCAD

SOLVED
Highlighted
Newbie

Writing Pseudocode in MATHCAD

I wrote pseudocode but don't know how to write it in Macthcad

Can you guys show me how would you write this in MATHCAD?

IF a>0 THEN

tol = 10^-5

x=a/2

DO

y=(x+a/x)/2

e=(y-x)/y

x=y

IF e<tol EXIT

END DO

SquareRoot=x

ELSE

SquareRoot=0

END IF

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Writing Pseudocode in MATHCAD

Hi,

Mathcad gives you the option to write sub-programs as functions, see attachement.

all of the program tools are available in the programming toolbar at the top of the mathcad window, most of them are replicated as short-cut key combinations:

Capture.PNG

Similar functions are available from the ribbon in MC prime, but (as far as I know) there are no short-cut keys

Otherwise the functionality should be similar (and translateable)

Note that when using the program feature it is the left arrow for assignement not :=

All variables used within the program can use variables already defined (above) in the work sheet unless otherwise redefined in the program or as parameters, but ONLY variables that are returned (as the example) will be accessible to the rest of the work sheet; all other assignement are only valid in the scope of the program fragment.

Hope this helps.

Andy

You could also write a function to compare and swap strings ( as your other post) - a for loop or while loop would allow you to iterate through the array.

Message was edited by: A Westerman

2 REPLIES 2

Re: Writing Pseudocode in MATHCAD

Here is an example.

I added a version that accounts for negative input values.

Re: Writing Pseudocode in MATHCAD

Hi,

Mathcad gives you the option to write sub-programs as functions, see attachement.

all of the program tools are available in the programming toolbar at the top of the mathcad window, most of them are replicated as short-cut key combinations:

Capture.PNG

Similar functions are available from the ribbon in MC prime, but (as far as I know) there are no short-cut keys

Otherwise the functionality should be similar (and translateable)

Note that when using the program feature it is the left arrow for assignement not :=

All variables used within the program can use variables already defined (above) in the work sheet unless otherwise redefined in the program or as parameters, but ONLY variables that are returned (as the example) will be accessible to the rest of the work sheet; all other assignement are only valid in the scope of the program fragment.

Hope this helps.

Andy

You could also write a function to compare and swap strings ( as your other post) - a for loop or while loop would allow you to iterate through the array.

Message was edited by: A Westerman