Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
Hi there ,
To be honest I don't even know
I need to multiple selective values in a matrix with selective values in another matrix . I used ( submatrix function ) however it didn't work :
where m is a row number
Here I want mathcad to multiple the first three values from both d and z
Can you help me doing this ? the sheet is attached
Thanks
Yusra
Solved! Go to Solution.
Sorry Yusra used subscript "1" not subscript "i" for z
Correction:-
Cheers
Terry
Sorry Yusra used subscript "1" not subscript "i" for z
Correction:-
Cheers
Terry
Thank you Terry . I appreciate your help
Functions are helpful if you might want to do this more than once and/or with different value of m.
Stuart
Thank you Stuart . So I should make them first vectors than use this solution
You already got your solution. I just wanted to explain why your approach did not work. Reason is that you used the vectors which are created as a subscript - hence the error message as a subscript must be an integer.
Your approach works OK if you just multliply the results of the subscript functions.
Here the vector dot product is used by Prime:
If you had an element-wise multiplication in mind so the result is again a vector, you would have to use vectorization:
But I am a little irritated as you use a value in vector dz as the number of elements to multiply. What if you would have chosen m:=dz2 instead of m:=dz3 ?? Obviously its not possible to multiply the first seven elements as dz contains only six elements. You may replace m by min(m, last(z), last(dz) to cope with this.
And I sure agree with Stuart that using a function to do the job could be quite beneficial.
You may use a more generic one which multiplies a contiguous range given the start and end index:
Or you could do without submatrix and vectorization by using a simple for-loop
Both functions don't use any error checking as of invalid indices...
Thank you Werner. actually in my original sheet m is not a simple number . It is also a function . I wonder if I can use the submatrix function in matrix index
@YA_10963798 wrote:
Thank you Werner. actually in my original sheet m is not a simple number . It is also a function .
Hopefully a function that returns an integer in the range from 1 to the length of the smaller of the two vectors.
I wonder if I can use the submatrix function in matrix index
Sorry, its not clear to me what this should mean and also not how it would relate to the picture you posted.
The submatrix function always returns a vector or matrix but the index for a matrix always must be a simple integer.
something like this , just to keep the sheet shorter so I don't have to write new stuff >>
actually you answered that here
Thank you
Could you use lookup directly to return the values you want, Yusra? Or can this present other problems?
Stuart
Is lookup function different than select ?
Principle of maximal laziness:
You only have to type the vector in as an argument to Select once!
Also, if I were writing in Mathcad Prime, I'd have put error trapping for the case where lookup doesn't find any matches. Lookup raises an error, whereas I'd normally return zero for no matches.
Stuart
Of course, if I was developing Select to be more general, I'd have also included an option for it choose whether to lookup or choose.
And talking of Works in Progress and Mathcad Express not being able to deal with match's error conditions ...
I've got versions of lookup, vlookup, hlookup, and vhlookup almost ready -- they are scattered all over my development worksheet and need consolidating, whereas match & Match were ready for beta test.
Stuart
that's great
Thank you so much
