Invalid Array
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Invalid Array
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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):
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Try removing left square bracket above the red arrow.
Martin Hanák
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi,
"red" expression is different from others.
Martin Hanák
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi,
I think you have to upload your Mathcad file.
Martin Hanák
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Interesting
How to solve that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hahaha ,,, it is up to you.
Martin Hanák
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
If I knew how to solve, I wouldn't ask ;(
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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):
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thank you so much you are always a life saver.
