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

For loop iterating over a matrix

SOLVED
SB_9890617
Visitor

For loop iterating over a matrix

I'm trying to iterate over a matrix and for some reason I can't seem to generate the new matrix. It just spits out the last value of the iteration.

Looking at other posts I think I have something wrong with the indices of the matrix, but I can't quite figure it out.

 

SB_9890617_0-1617810428796.png

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: For loop iterating over a matrix

4 REPLIES 4

Re: For loop iterating over a matrix

Re: For loop iterating over a matrix

Thank you, very much!

Re: For loop iterating over a matrix

The result of a program is the last statement executed. In your case that's the assignment of the last element to the array omega. So the result is that last element.

If you add just omega after the for loop, as what MFra showed, you get the entire array.

Note that there is a specific keyword: 'return' that you can use to define the result of a function. Put anywhere in the function, the item placed as the argument to 'return' is the result of the program. Also be aware that 'return' also stops execution of the program. So if you use it within a program construct (If, For or whatever) the program stops there.

But putting it on the last line of a program certainly is no crime.

 

Success!
Luc

Re: For loop iterating over a matrix

Thank you very much for the in depth explanation!

Announcements
Check out the latest
Mathcad Tip
"PTC Mathcad 15 / Prime 1-6 Update."