cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Translate the entire conversation x

Multiple selective values two matrix

YA_10963798
14-Alexandrite

Multiple selective values two matrix

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 

YA_10963798_0-1762164165901.png

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 

 

ACCEPTED SOLUTION

Accepted Solutions

Sorry Yusra used subscript "1" not subscript "i" for z

Correction:-

Capture.JPG

Cheers

Terry

View solution in original post

14 REPLIES 14

Like this Yusra:-

Capture.JPG

Cheers

Terry

Sorry Yusra used subscript "1" not subscript "i" for z

Correction:-

Capture.JPG

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.

 

2025 11 03 A.png

 

Stuart

 

YA_10963798
14-Alexandrite
(To:StuartBruff)

Thank you Stuart . So I should make them first vectors than use this solution 

Werner_E
25-Diamond I
(To:YA_10963798)

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:

Werner_E_0-1762179381817.png

If you had an element-wise multiplication in mind so the result is again a vector, you would have to use vectorization:

Werner_E_1-1762179472644.png

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:

Werner_E_2-1762180913301.png

Or you could do without submatrix and vectorization by using a simple for-loop

Werner_E_3-1762180972966.png

Both functions don't use any error checking as of invalid indices...

 

YA_10963798
14-Alexandrite
(To:Werner_E)

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_0-1762181722532.png

 

 

Werner_E
25-Diamond I
(To:YA_10963798)


@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.

YA_10963798
14-Alexandrite
(To:Werner_E)

something like this , just to keep the sheet shorter so I don't have to write new stuff >> 

YA_10963798_0-1762189552859.png

actually you answered that here

YA_10963798_1-1762189657879.png

Thank you 

 

 

Could you use lookup directly to return the values you want, Yusra?  Or can this present other problems?

 

2025 11 03 C.png

 

Stuart

YA_10963798
14-Alexandrite
(To:StuartBruff)

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.

 

2025 11 03 G.png

 

And talking of Works in Progress and Mathcad Express not being able to deal with match's error conditions ...

 

2025 11 03 E.png

 

2025 11 03 F.png

 

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

YA_10963798
14-Alexandrite
(To:StuartBruff)

that's great 

Thank you so much 

Announcements

Top Tags