Skip to main content
1-Visitor
November 16, 2013
Solved

While loop doesn't work

  • November 16, 2013
  • 1 reply
  • 4199 views

Hi!

Does anybody have any suggestions why the iteration in the while loop doesn't work.

The return value of "iter" shouldn't be 1. It seems like the iteration doesnt work. I have basically translated this from a matlab script with the exception changing the equations to functions to put in the loop.

Could anyone see a deviation in the script?

Thanks in advance!

Best answer by Werner_E

Some additional remarks concerning your sheet.

The call to the functions STEP4a and b are always returning the same value because the calling parameter does not change (as far a I can tell) and the other variables used in the function definition are those at the time of defining the function, so they don't change.

The variable v.xy is not defined but used right at the beginning of your program for a comparison in the outer while loop. v.xy has to be assigned an initial value.

Line like f.sy <-- f.sy have no effect in Mathcad. What do you think that should happen here?

The outer while loop ends in a return statement. This statement stops the whole program, so the loop has no effect.

If you asign v.xy an initial value at the top of the program and delete the inner return statement so the outer loop may make sense, your program performs a lot of iterations until it fails because v.xy gets complex and (the outer while) you cannot compare complex numbers for size.

1 reply

25-Diamond I
November 17, 2013

Its one of the break commands which cancels the while loop at the very beginning.

You can use the trace command to debug that kind of programs.

Any reason you wrote the condition for the while loop so complicated (with an if)?

17.11.png

Ermis761-VisitorAuthor
1-Visitor
November 17, 2013

Thanks!!

I will take a closer look at the commands which cancels the while loop.

The only reason the condition is met with an if is because it was written that way in the original matlab script. i have practically translated the script to mathcad.

Do you have any suggestions how to simplify?

Regarding the trace command how do i find more information about how to use it?

25-Diamond I
November 17, 2013

The only reason the condition is met with an if is because it was written that way in the original matlab script. i have practically translated the script to mathcad.

Do you have any suggestions how to simplify?

I did it for this loop, see at the top of the screenshot. The if worked that way because 0 is considered to be FALSE and anything else (e.g. 1) is TRUE.

Regarding the trace command how do i find more information about how to use it?

The built-in help is quite informative. Search for and look at the chapter on "Program Debugging". There even is link to a tutorial. Basically there are just two commands available you can use (trace and pause) and you have to know how to turn on debugging (Tools/Debug/Toggle Debugging).