Matrix does not want to multiply and gives an error when I multiply a 3x3 matrix with a 3x1 matrix
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
Steven Lord
2024-5-16
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
回答(4 个)
Voss
2024-5-8
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 个评论
sai charan sampara
2024-5-8
编辑:sai charan sampara
2024-5-8
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 个评论
Ahmed Abed
2024-5-16
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 个评论
Stephen23
2024-5-16
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!