Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
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!
Solved! Go to Solution.
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.
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)?
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?
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).
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.
Thanks again for your remarks!
Correct, the f.sy<--- f.sy has no effect, may as well remove it.
"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"
Werner, is it possible to post a screenshot for the above explanation?
Haven't saved the file but it should not be that difficult.
1) assign v.xy a value, either before the program or a the first line in the program before the while statement. I had chosen v,xy<--1, don't know if that makes any sense at all.
2) delete the last but one return statement (the "inner" one inside of the first while)
Now you should get an error at the to (the comparison in the first while) that you cannot compare that value - this is due to the fact that v.xy isn't a real anymore.
3) To see the values v.xy place a trace(v.xy) line somewhere, maybe at the same positon you just deleted the return statement.
4) Toggle debugging and let the program recalculate (F9). Now you see the values of v.xy running through and you nedd a lot of patience. I stopped before it ended so I can only guess that v.xy is going complex sooner or later.
Here is a modified file. The outer loop now stops when v.xy is getting complex so you can see the values calculated so far at the end of the file.
How good do you know or how well versed are you with the algorithm you are trying to implement here?
Wow, thanks this helps me a lot!! I have a working loop now
Regarding the algorithm. I think i'm quite familiar to what i'm trying to implement or achieve. The problem is my programming skills.
It all originates from here, see the attached, (for comparison, σ is f in the attached ). It paints a picture of what i'm trying to achieve with the loop, i hope.
Thanks again for the help!
Wow, thanks this helps me a lot!! I have a working loop now
You are welcome, Evangelos
You have a working loop, but I doubt that is does what it should as I guess v.xy is not supposed to get complex in the Matlab implementation.
It all originates from here, see the attached, (for comparison, σ is f in the attached ). It paints a
Yes, I remember that file from a prior posting of yours. Was too confusing for me.