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

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Inquiry regarding matrix multiplication

Germán
5-Regular Member

Inquiry regarding matrix multiplication

Dear Mathcad community,

 

I am writing my first post on this forum in the hope that someone can assist me with a question. Firstly, I would like to say that I am using Mathcad Prime 9.0.0.0. and I am attempting to multiply two matrices and I am struggling to achieve my objective. I want to multiply matrix A (with i rows and j columns) by matrix B (with j rows and 1 column), in order to obtain matrix C as shown in the image (with i rows and j columns). Subsequently, I aim to determine the maximum value of each row in later.

 

Thank you very much in advance for your assistance.

 

Sincerely, Germán.

 

Captura de pantalla 2024-05-09 091212.png

1 ACCEPTED SOLUTION

Accepted Solutions

Oh my goodness!
That's another one of those "Why didn't I think of that in the first place?" moments!

 

The easiest way to create the matrix you are looking for sure is

Werner_E_0-1715248378268.png

without having to write and use any 'create'-function.

You may also use it with symbolic evaluation if you need to do so

Werner_E_1-1715248770027.png

 

The get the max values of each row you may still use the function I posted before.

View solution in original post

5 REPLIES 5
ttokoro
20-Turquoise
(To:Germán)

image.pngimage.pngimage.pngimage.pngimage.pngimage.pngimage.pngimage.pngimage.png

Germán
5-Regular Member
(To:ttokoro)

Thank you ttokoro for your reply. I don't know the reason why your solution doesn't work well in my Mathcad, probably I implemented it in a wrong way:

Captura de pantalla 2024-05-14 081419.png

But it gave me an idea to solve it, as follows:

Captura de pantalla 2024-05-14 081518.png

Thank you very much.

@ttokoro

Wouldn't it be much easier to simply use

Werner_E_2-1715247211825.png😉

 

@Germán 


@Germán wrote:

 I am attempting to multiply two matrices

NO!! You are NOT looking for matrix multiplication. Prime knows how to multiply two matrices (given the dimensions are correct) but what you are looking for is NOT called matrix multiplication.

So its best to write a small user-function which takes the two matrices as its input and return a matrix according to your specifications.

The same applies for the max values in each row.

Here are my suggestions (note that there is no error checking implemented to throw an error if the matrix dimensions are not correct (second matrix is only allowed one column and must have same number of rows as are columns in the first matrix):

Werner_E_0-1715245710510.png 
Werner_E_1-1715245725011.png

Usage:

Werner_E_3-1715245799294.png

Werner_E_4-1715245837324.png

 

If you think that its more convenient you may combine the two function in just one:

Werner_E_5-1715245895988.png

Werner_E_6-1715245935979.png

 

EDIT: Added a tricky alternative for "create" which does not use any explicit loops at all:

Werner_E_3-1715247549879.png

 

Werner_E_1-1715246644003.png

 

Prime 9 worksheet attached

Oh my goodness!
That's another one of those "Why didn't I think of that in the first place?" moments!

 

The easiest way to create the matrix you are looking for sure is

Werner_E_0-1715248378268.png

without having to write and use any 'create'-function.

You may also use it with symbolic evaluation if you need to do so

Werner_E_1-1715248770027.png

 

The get the max values of each row you may still use the function I posted before.

Germán
5-Regular Member
(To:Werner_E)

Thank you very much for your solution. I tested both solutions and it works well:

Captura de pantalla 2024-05-14 082455.png

I also took advantage of your program 'rowmax' to get the minimum values too

Captura de pantalla 2024-05-14 082637.png

 

Top Tags