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

4 views (last 30 days)
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

Answers (2)

Walter Roberson
Walter Roberson on 3 Oct 2022
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 Comment
Alina Abdikadyr
Alina Abdikadyr on 3 Oct 2022
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

Sign in to comment.


Torsten
Torsten on 4 Oct 2022
Edited: Torsten on 4 Oct 2022
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 Comments
Torsten
Torsten on 4 Oct 2022
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

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!