Skip to main content
1-Visitor
June 13, 2017
Question

Returning multiple variables from a while loop

  • June 13, 2017
  • 1 reply
  • 4918 views

Hi,

I have been trying to get a while loop to augment multiple matrices, previously defined globally,  until convergence is reached. I then want to access these matrices outside of the loop to perform further calculations. I have been having no luck, and am not even sure if I have defined the loop correctly to draw from the global variables. If you have any ideas, i would be incredibly appreciative.
Thanks so much,

1 reply

23-Emerald IV
June 13, 2017

Your function Convergence() takes alot of parameters, but it is ill defined.

Success!
Luc

1-Visitor
June 14, 2017

Great, Thanks Luc.

If I were to create this loop without parameters, would I be able to access the global variables from within the loop? Would I have to locally assign them to another variable within the loop?

Thanks so much,

23-Emerald IV
June 14, 2017

In programs, Mathcad works with variables much like ordinary programming languages do.

If you use a variable, and it is defined (and has a valid value) within the program, that value will be used.

If it is not defined within the program, Mathcad will use a global variable (defined left/above the start of the program) if it exists.

If it can't find the variable in either way, an error results. Here is a simple example of a function that results in a value dependent on a global, and a local variable and a parameter.

Now if you change the function like this:

You see that the global parameter is not used, but it still exists outside of the function.

Success!
Luc