Solving a system of linear equations with a few known variables
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Deepa Maheshvare
am 11 Dez. 2018
Kommentiert: AKASH BHOYAR
am 19 Mai 2022
I'm solving the following system of linear equations,
Ax = b, some of the x's are knowns.
For example,
A=
-12 12 0 0 0
0 -1 1 0 0
0 0 -0.5 0.5 0
0 0 0 -17 17
x = [x1 x2 x3 x4 x5]
b = [b1 0 0 0 b5]
When some of the variables are known, say x1 and x5 are known, the system can be reduced in terms of the known variables. However, when there are around 50 variables and 5 are known re-writing the matrix in terms of the known variables is difficult.
I would like ask for suggestions on alternate ways of solving these kind of linear systems in which the values of a few variables are known.
2 Kommentare
KSSV
am 11 Dez. 2018
To solve b should be having a length equal to rows of A. Read about mldivide i,e \
Akzeptierte Antwort
Bruno Luong
am 11 Dez. 2018
Bearbeitet: Bruno Luong
am 11 Dez. 2018
Assuming known is the logical index == TRUE for indexes of x that are known
% known = ismember(1:5,[1 5]) % in your example
x(known) = XValueYouKnow;
x(~known) = A(:,~known) \ (b-A(:,known)*x(known))
1 Kommentar
Weitere Antworten (1)
madhan ravi
am 11 Dez. 2018
Bearbeitet: madhan ravi
am 11 Dez. 2018
See https://in.mathworks.com/matlabcentral/answers/297297-how-to-solve-a-system-of-equations-in-the-matlab?s_tid=answers_rc1-2_p2_MLT#answer_230057 for detailed discussion.
One way using solve():
syms x1 x2 x3 x4 x5 b1 b5
eqn=[ -12*x1+12*x2==b1;
-x2+x3==0;
-0.5*x3+0.5*x4==0;
-17*x4+17*x5==b5];
[x1,x2,x3,x4]=solve(eqn)
Second way using linsolve():
syms b1 b5
A=[ -12 12 0 0 0
0 -1 1 0 0
0 0 -0.5 0.5 0
0 0 0 -17 17];
b = [b1;0;0;b5];
[x,R]=linsolve(A,b)
Third way using mldivide():
syms b1 b5
A=[ -12 12 0 0 0
0 -1 1 0 0
0 0 -0.5 0.5 0
0 0 0 -17 17];
b = [b1;0;0;b5];
A\b % x5 has infinity number of solutions I guess
10 Kommentare
madhan ravi
am 11 Dez. 2018
My suggestion was already stated https://in.mathworks.com/matlabcentral/answers/435087-solving-a-system-of-linear-equations-with-a-few-known-variables#comment_648869
Siehe auch
Kategorien
Mehr zu Contour Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!