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.
one thing against vectors. the worksheet becomes less readable, with tons of 0's and 1's floating around.
Not sure what you mean by that, can you post an example?
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.
for eg
i:=(1 2 3 4)
to pick 2 i have to do i[0,1]
Not true have a look at the attached image.
Btw how do i find sum of a vector. or sum of one column of a 2D array