I'm having a problem figuring out how to do some math on a subset of a vector. I have some data that I want to store in a variable (range or vector). I want to be able to perform some simple math on portions of that variable, but it's not working the way I'd expect.
(I apologize, I don't know how to add mathcad notation in this forum)
Example.
I have 4 elements I'm storing in a variable called row (row = 1,3,7,15) using range variables ii=0..3
I want to take the 2nd through 4th element and subtract off the 1st through 3rd element and store that in a new variable which would have the result of newrow = 2,4,8
I thought I could just do the following
jj=1..3
kk = 0..2
newrow[kk = row[[jj - row[[kk
but I get an error saying jj should be an integer.
What am I missing?
Thanks!
Solved! Go to Solution.
How about this?
That looks like it's what I want to do. Now the question is, why does it have to be done that way? Why doesn't my way work as it looks to be doing basically the same thing?
In your attempt, Mathcad was trying to apply the entire range jj to each element of newrow. For example, the way you wrote the equation, Mathcad tried to calculate the following for the first element (kk=0) of newrow:
Another option is to use the submatrix function:
Luc
If you are not using the crippled Express version, you may also consider using a user defined function: