Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
Hello. I am looking for some assistance with for loops and matrices within Mathcad. I have a relatively basic knowledge of mathcad so this may be a straightforward solution.
I am trying to return a value for m11 for each of the sigma(11) values. However, the way i have it set up, it only returns the m11 value when i = 2.
I know i could list the equation out 3 times, changing the "i" with 0, 1, and 2 each time; however i had thought i may be able to do the same thing using the for loop function.
Thank you.
Solved! Go to Solution.
A Mathcad program returns ONLY the value of the last statement executed. That's why you see a single element instead of an array.
Here's what you could do (simplified):
(I could have typed just R, instead of return R, but it makes clear what result the program should return. Note that a return statement put anywhere in the program makes the program stop there and return the argument of the return. So you can put it in a IF statement if you need to stop the program in the middle of a loop.)
But in general I prefer to define a function (prevents strange things happening when the FOR loop gets out of sync with the length of the array):
A word of advice: refrain from evaluating a definition (that is, do NOT put an = immediately following a definition, like you did with m.11). First define m.11 := ....
Then, on a separate spot, evaluate it with m.11 =
Yes, it works (most of the time), but occasionally it creates problems.
Success!
Luc
A Mathcad program returns ONLY the value of the last statement executed. That's why you see a single element instead of an array.
Here's what you could do (simplified):
(I could have typed just R, instead of return R, but it makes clear what result the program should return. Note that a return statement put anywhere in the program makes the program stop there and return the argument of the return. So you can put it in a IF statement if you need to stop the program in the middle of a loop.)
But in general I prefer to define a function (prevents strange things happening when the FOR loop gets out of sync with the length of the array):
A word of advice: refrain from evaluating a definition (that is, do NOT put an = immediately following a definition, like you did with m.11). First define m.11 := ....
Then, on a separate spot, evaluate it with m.11 =
Yes, it works (most of the time), but occasionally it creates problems.
Success!
Luc
Thank you for providing this. Very useful information to know for the future. Managed to make both work for my problem too
Thank you for this. Capture 1 works best for me as it was very similar to how the actual calculation I have was laid out.
For those who have similar problems but only have Mathcad Prime Express, here are a few other ways around using programmed for loops. They work in Mathcad Prime Express 7 and should work in earlier versions.
Stuart