Matrix does not want to multiply and gives an error when I multiply a 3x3 matrix with a 3x1 matrix
5 views (last 30 days)
Show older comments
A=[9,29.3, 140.99; 29.3, 140.99,827.693; 140.99, 827.693, 5400.863]
Ainv=inv(A); % inverse matrix
B=[4.6;-16; -267.29] % B matrix used in A^-1*B
values = B * Ainv %multiply the matrix to get a and b
the multiplication does not want to multiply
1 Comment
Steven Lord
on 16 May 2024
There's no need to call inv here and multiply. Yes, I know that's probably what you were taught in school, but to use A to solve a system of equations A*x = b compute x = A\b instead.
format longg
A=[9,29.3, 140.99; 29.3, 140.99,827.693; 140.99, 827.693, 5400.863]
B=[4.6;-16; -267.29]
values = A\B
checkThatAxEqualsB = A*values-B % Should contain values very close to 0
Answers (4)
Voss
on 8 May 2024
Do Ainv*B not B*Ainv
A=[9,29.3, 140.99; 29.3, 140.99,827.693; 140.99, 827.693, 5400.863]
Ainv=inv(A) % inverse matrix
B=[4.6;-16; -267.29] % B matrix used in A^-1*B
values = Ainv*B %multiply the matrix to get a and b
0 Comments
sai charan sampara
on 8 May 2024
Edited: sai charan sampara
on 8 May 2024
Hello Gihahn,
In line 2 "mat1" is not defined. If you want to have the inverse of "A" replace it with A. Also the size of "B" is 3x1 and "A" is 3x3 matrix. So trying to multiply "B" with "A" will give an error. You can take the transpose of "B" and then multiply with "A" or change the order of multiplication for the dimensions to agree for multiplication.
A=[9,29.3, 140.99; 29.3, 140.99,827.693; 140.99, 827.693, 5400.863]
Ainv=inv(A); % inverse matrix
B=[4.6;-16; -267.29] % B matrix used in A^-1*B
values = B' * Ainv
values = Ainv*B
0 Comments
Ahmed Abed
on 16 May 2024
You are multiplying [3x1] matrix by [3x3] one, which is mathmatically incorrect.
If you try values = Ainv*B then you will get an answer (not sure if it is what you wanting).
0 Comments
Stephen23
on 16 May 2024
Read the INV documentation! And then use the recommended function MLDIVIDE:
A = [9, 29.3, 140.99; 29.3, 140.99,827.693; 140.99, 827.693, 5400.863];
B = [4.6; -16; -267.29]
C = A\B
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!