필터 지우기
필터 지우기

Extract values from one matrix and with iteration solve the system of linear equations

조회 수: 1 (최근 30일)
Hello everyone!
Please, help me write a code for solving the system of linear equations in Matlab
If I have a column of coefficients A [A1;A2;A3] and the inverse matrix 3x3 B^(-1) and unknown column C [C1, C1, C1] (here all values are equal)
I have to find C1 value and plot the graph. Also A1 values can be extraacted from another matrix, so unknowns are A2, A3 and C1
A.'*B^(-1) = C

답변 (2개)

Walter Roberson
Walter Roberson 2022년 10월 3일
A = randi([-5 5], 5 ,3)
A = 5×3
0 -4 -5 5 3 -4 -1 -1 0 4 3 -5 5 4 -4
B = randi(9,3, 3)
B = 3×3
4 8 7 1 1 9 9 6 1
C = A/B
C = 5×3
-0.7494 -0.0098 0.3342 -0.0319 -0.4889 0.6241 -0.0663 0.0614 -0.0885 0.1057 -0.6904 0.4742 0.1646 -0.6339 0.5528
plot(C(:,1))
  댓글 수: 1
Alina Abdikadyr
Alina Abdikadyr 2022년 10월 3일
Thank you for your answer! but A2 and A3 coefficients for me are unknown. So (A1, A2, A3)*B matrix = (C1,C1,C1). I should find A2, A3 and C1

댓글을 달려면 로그인하십시오.


Torsten
Torsten 2022년 10월 4일
편집: Torsten 2022년 10월 4일
B = rand(3,3);
A1 = 4;
rhs = -A1*B(1,:).';
Mat = [-ones(3,1),B(2:3,:).'];
sol = Mat\rhs;
C1 = sol(1)
C1 = 9.4544
A2 = sol(2)
A2 = 80.7027
A3 = sol(3)
A3 = -250.8747
[A1 A2 A3]*B-[C1 C1 C1]
ans = 1×3
1.0e-14 * -0.3553 -0.3553 -0.7105
  댓글 수: 3
Torsten
Torsten 2022년 10월 4일
Use a loop:
B = rand(3,3);
A1 = [4,pi,-80,329];
C1 = zeros(size(A1));
A2 = zeros(size(A1));
A3 = zeros(size(A1));
for i=1:numel(A1)
rhs = -A1(i)*B(1,:).';
Mat = [-ones(3,1),B(2:3,:).'];
sol = Mat\rhs;
C1(i) = sol(1);
A2(i) = sol(2);
A3(i) = sol(3);
[A1(i) A2(i) A3(i)]*B-[C1(i) C1(i) C1(i)];
end
C1 = 1×4
-10.8402 0 0 0
A2 = 1×4
-19.4251 0 0 0
A3 = 1×4
-0.3832 0 0 0
ans = 1×3
1.0e-14 * -0.1776 -0.1776 0
C1 = 1×4
-10.8402 -8.5139 0 0
A2 = 1×4
-19.4251 -15.2565 0 0
A3 = 1×4
-0.3832 -0.3009 0 0
ans = 1×3
1.0e-14 * 0 -0.1776 -0.1776
C1 = 1×4
-10.8402 -8.5139 216.8035 0
A2 = 1×4
-19.4251 -15.2565 388.5023 0
A3 = 1×4
-0.3832 -0.3009 7.6631 0
ans = 1×3
1.0e-13 * -0.2842 -0.2842 0
C1 = 1×4
-10.8402 -8.5139 216.8035 -891.6043
A2 = 1×4
1.0e+03 * -0.0194 -0.0153 0.3885 -1.5977
A3 = 1×4
-0.3832 -0.3009 7.6631 -31.5146
ans = 1×3
1.0e-12 * 0 0 -0.1137

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by