I think this might be a bug, because if you pass a range explicity, i.e., 1,2..3, then the function works, but if you pass it by reference, i.e., j, where j:=1,2..3, then you get the error message, and it is the called function that is complaining. The summation works standalone, but when it is in a function, the summation complains that the passed variable is not a range, though is clearly is.
While the behavior is buggy, the function definition is unclear to me. Making the summand a range seems to me to be not a valid construct. What does
sum(0..n) from 0..n mean exactly?
Since it does accept the range definition directly, it should accept it by reference, so that's a bug. The construct was allowed in M11, resulting in an array of the summation of the range, i.e., n*(n+1)/2 n+1 times, That's rather pointless, and so maybe that's why it was changed, but it doesn't throw a useful error message.
Since it does accept the range definition directly, it should accept it by reference, so that's a bug. The construct was allowed in M11,
Sort of. The range variable actually has to be defined before the function defintion, because the summation variable and the variable to be summed are not the same, even if they have common names:
resulting in an array of the summation of the range, i.e., n*(n+1)/2 n+1 times, That's rather pointless, and so maybe that's why it was changed, but it doesn't throw a useful error message.
Thanks. Now I understand what it is doing in MC11. In the image above, the sum over all i, k+1 times. As you say, not a very useful answer!
You've stumbled into the murky waters of range variables in Mathcad. In some ways, it is nice that they work the way they do, and that they are distinct from vectors. At other times, they are annoying [to me] to work wth, because I expect a certain behavior and don't get it.
In the attached file, I show the examples that I could think of, and conclude that there is no programmatic solution needed. Let us know what you think...
...and if you want to know the number of elements in the range, replace the summation argument k in the last example with 1, and the result is the number of elements in the range.
converting my entire worksheet into vector is going to be a chore.
But i guess it will be worth it. these range variables are becoming a nuisance.
one thing against vectors. the worksheet becomes less readable, with tons of 0's and 1's floating around.
I noticed even if you create a vector you still have to use two indexes to pick an element from the vector, just like what you would use for a 2D array.
Hi, Can you tell me why this summation is not working?
Not without seeing how you defined the vector E (did you use vector indices, not literal ones?), how you set the value of ORIGIN (did you change it from the default 0 to 1?) and how your variables are labeled. We would need the worksheet to check the latter.
In any case it would be preferable that you open a new thread and attach your worksheet, too.
BTW, if your vector E only consists of the three elements, its easier to use the summation operator without any range i: