I worte the same program for seven function and it works in all of them ,but doesn't work in the last one. I have no clue why?
Do you see the problem? There is no difference , HOWEVER the error shows only in last one.
Solved! Go to Solution.
As Martin already noticed is the reason for this error that the largest value in vector K7 is the last value. Your program then tries to access the values after that element but because its the last value, the values you try to access do not exist - hence the error.
Simple solution is to use an if-statement to deal with that single situation. The loop is only entered when the maximum value is not the last in the vector. Otherwise the vector is returned unchanged.
But its quite inefficient to write a separate program for each of the six variables K2 to K7.
I would strongly suggest to write ONE function (which you could place anywhere above, maybe in a collapsed region) and use this function to calculate the six vectors:
You sure will want to name the function differently 😉
What was your intention with the next calculation?
I guess you wanted to sum up all the values in vector K2, right.?
So you made two errors:
1) you add "j" to the variable "sum", but you do not re-assign the result to the variable "sum". So "sum" remains zero
2) You do not provide a return value, so the program returns the last value it deals with and thats in your case just the last value in vector K2
Here is a corrected version
But it would be much easier to use the sum operator which Prime offers out of the box (simply don't fill the placeholders at the bottom and the top of the Sigma symbol):
Try removing left square bracket above the red arrow.
Hi,
"red" expression is different from others.
Hi Martin,
Actually I just copied paste the same program for all of them and changed the numbers. It works in all of them only the last one . When I did what you recommended it didn't work either, Why do you think it doesn't work only in the last one?
Regards,
Yusra
Hi,
I think you have to upload your Mathcad file.
Interesting
How to solve that?
Hahaha ,,, it is up to you.
If I knew how to solve, I wouldn't ask ;(
As Martin already noticed is the reason for this error that the largest value in vector K7 is the last value. Your program then tries to access the values after that element but because its the last value, the values you try to access do not exist - hence the error.
Simple solution is to use an if-statement to deal with that single situation. The loop is only entered when the maximum value is not the last in the vector. Otherwise the vector is returned unchanged.
But its quite inefficient to write a separate program for each of the six variables K2 to K7.
I would strongly suggest to write ONE function (which you could place anywhere above, maybe in a collapsed region) and use this function to calculate the six vectors:
You sure will want to name the function differently 😉
What was your intention with the next calculation?
I guess you wanted to sum up all the values in vector K2, right.?
So you made two errors:
1) you add "j" to the variable "sum", but you do not re-assign the result to the variable "sum". So "sum" remains zero
2) You do not provide a return value, so the program returns the last value it deals with and thats in your case just the last value in vector K2
Here is a corrected version
But it would be much easier to use the sum operator which Prime offers out of the box (simply don't fill the placeholders at the bottom and the top of the Sigma symbol):
Thank you so much you are always a life saver.