1x4 times 4x4 matrix in Matlab

159 views (last 30 days)
Fleur van Delft
Fleur van Delft on 11 Dec 2020
Commented: Fleur van Delft on 11 Dec 2020
Hi!
I have a 4x4 matrix (say P) and I need to multiply it with a 1x4 (say A) matrix. I saw the answers that I needed to do P*A' to get the right answer. But when I do that it is not the right solution, so did I maybe fill in wrong numbers in the matrix is that my mistake or is there another way to solve this multiplication?
  3 Comments
Stephen23
Stephen23 on 11 Dec 2020
Edited: Stephen23 on 11 Dec 2020
"I have a 4x4 matrix (say P) and I need to multiply it with a 1x4 (say A) matrix."
According to the rules of matrix multiplication
the two adjacent dimensions must be the same. This means it is not possible to multiply a 4x4 matrix with a 1x4 matrix, but it is possible to multiply 4x4 by 4x1 to get a 4x1 matrix or 1x4 by 4x4 to get a 1x4 matrix. Which of these, if any, are correct for your situation depends on you knowing what operation you need to perform. It is also possible the matrix multiplication is entirely the wrong operation (perhaps you should be doing element-wise array multiplication?).
"But when I do that it is not the right solution, so did I maybe fill in wrong numbers in the matrix is that my mistake or is there another way to solve this multiplication?"
It is not clear what you mean by "solve this multiplication": from what you have told us so far we have no idea what exact values you tried, what exactly you expect the output to be, and how you checked the output, or even if this operation is suitable at all. Perhaps you are getting some floating point issues... we don't know, because you didn't show what you are doing nor what you expect.
Matrix multiplication does not need to be "solved", it already works according to the standard accepted definition.
Fleur van Delft
Fleur van Delft on 11 Dec 2020
I solved it already! Thanks for your help it made me solve the question. Thanks again

Sign in to comment.

Answers (1)

Daniel Pollard
Daniel Pollard on 11 Dec 2020
Use the rules for matrix multiplication to help you. What solved one persons problem won't always solve yours.
A 4x4 multiplied by a 4x1 should work. A 4x4 multiplied by a 1x4 won't. In your case, P*A will return an error, but P*A' shouldn't.
If you copy and paste your code and any error messages, it makes it much easier to provide a comprehensive answer.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!