Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
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.
Solved! Go to Solution.
Thank you, very much!
(Nvm, solved it)
Hello,
Sorry to ask again.
I thought I had it figured it out, but when trying to replicate it on mathcad 15 it refuses to work.
I have one file that works and another that doesn't.
I've spent too much time trying to figure it out, and I'm getting nowhere.
1.
It is very hard to debug pictures. => You should ALWAYS attach the worksheet.
2.
The left one (the one that works) normally shouldn't work, because the last statement is an assignment to the last element of w, it should result in that last element's value. However I (seem to) see that you're using two different v's in the program (one to define the range and to index the y, the other as an index or subscript to w).
3.
To the right, the first one does not work for the reason as explained under 2. Now you're using the same v in all three places.
The second isn't right, you should not include the single 'w' inside the for loop, but outside of it.
The third is (or, at least, looks like) how it should be. I wonder why that one does not work.
One word of advice: The programming tools has this nice item called 'return', you should use it to define the return value of the function, that way you have better control over what is returned,
and you can see when you took the wrong route:
Success!
Luc
Sorry I completely forgot to upload the files.
Thank you for the quick reply!
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
Thank you very much for the in depth explanation!