Skip to main content
14-Alexandrite
November 3, 2025
Solved

Multiple selective values two matrix

  • November 3, 2025
  • 3 replies
  • 837 views

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 

 

Best answer by terryhendicott

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

Correction:-

Capture.JPG

Cheers

Terry

3 replies

21-Topaz II
November 3, 2025

Like this Yusra:-

Capture.JPG

Cheers

Terry

21-Topaz II
November 3, 2025

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

Correction:-

Capture.JPG

Cheers

Terry

14-Alexandrite
November 3, 2025

Thank you Terry . I appreciate your help

23-Emerald V
November 3, 2025

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

 

14-Alexandrite
November 3, 2025

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

25-Diamond I
November 3, 2025

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

 

14-Alexandrite
November 3, 2025

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

 

 

25-Diamond I
November 3, 2025

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