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!