Skip to main content
15-Moonstone
Nov 3, 2025 10:07 AM UTC
Solved

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 

 

terryhendicott
21-Topaz II
Nov 3, 2025 10:38 AM UTC

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

Correction:-

Capture.JPG

Cheers

Terry

14 replies

terryhendicott
21-Topaz II
Nov 3, 2025 10:26 AM UTC

Like this Yusra:-

Capture.JPG

Cheers

Terry

Translate
terryhendicott
21-Topaz II
Nov 3, 2025 10:38 AM UTC

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

Correction:-

Capture.JPG

Cheers

Terry

Translate
15-Moonstone
Nov 3, 2025 10:42 AM UTC

Thank you Terry . I appreciate your help

Translate
23-Emerald V
Nov 3, 2025 1:47 PM UTC

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

 

Translate
15-Moonstone
Nov 3, 2025 2:54 PM UTC

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

Translate
Werner_E
25-Diamond I
Nov 3, 2025 2:44 PM UTC

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

 

Translate
15-Moonstone
Nov 3, 2025 2:58 PM UTC

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

 

 

Translate
Werner_E
25-Diamond I
Nov 3, 2025 3:08 PM UTC

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

Translate