Filter löschen
Filter löschen

How to solve multiple equation and get all value of the variable?

2 Ansichten (letzte 30 Tage)
This is the code
syms p1 p2 p3 p4 p5 a
R =[1 2 3 1 2;4 5 1 2 6;7 1 2 1 2;1 4 3 2 2;1 5 4 3 2];
I =[1 0 0 0 0;0 1 0 0 0;0 0 1 0 0;0 0 0 1 0;0 0 0 0 1];
pi =[p1 p2 p3 p4 p5];
e =[1;1;1;1;1];
a=[p1 p2 p3 p4 p5]*(I-R)^(-1)*e
t=a - 1
z=solve(t,p1) %get p1
A_0=[2 1 1 2 4;1 2 2 1 1;2 2 1 1 3;1 3 6 2 2;1 3 4 1 2];
B =[1 3 2 1 2;2 1 2 7 1;1 2 1 2 3;1 4 2 1 2;2 3 1 2 2];
y=pi*(A_0+R*B)
j =subs(y,p1,z) %substitude p1 to 5 equations
[A,Z]=equationsToMatrix(j,pi)
sol=double(A)\double(Z)
After run, i get this warning and solutions
Warning: Matrix is singular to working precision.
> In tes_matlab_baru (line 30)
sol =
-Inf
1.4983
-0.6005
3.7351
-5.4810
What i want to get is all value of pi, how to get it?

Akzeptierte Antwort

Torsten
Torsten am 1 Nov. 2022
Bearbeitet: Torsten am 1 Nov. 2022
p1 can be chosen arbitrarily since the corresponding column in the matrix A is zero.
(I set p1 = 1).
Note that sol does not satisfy A*sol = Z exactly since you have 5 equations for 4 unknowns (p1 does not count since it cannot influence the system).
syms p1 p2 p3 p4 p5 a
R =[1 2 3 1 2;4 5 1 2 6;7 1 2 1 2;1 4 3 2 2;1 5 4 3 2];
I =[1 0 0 0 0;0 1 0 0 0;0 0 1 0 0;0 0 0 1 0;0 0 0 0 1];
pi =[p1 p2 p3 p4 p5];
e =[1;1;1;1;1];
a=pi*(I-R)^(-1)*e
a = 
t=a - 1
t = 
z=solve(t,p1) %get p1
z = 
A_0=[2 1 1 2 4;1 2 2 1 1;2 2 1 1 3;1 3 6 2 2;1 3 4 1 2];
B =[1 3 2 1 2;2 1 2 7 1;1 2 1 2 3;1 4 2 1 2;2 3 1 2 2];
y=pi*(A_0+R*B)
y = 
j =subs(y,p1,z) %substitude p1 to 5 equations
j = 
[A,Z]=equationsToMatrix(j,pi)
A = 
Z = 
sol = lsqlin(double(A),double(Z),[],[],[1 0 0 0 0],1)
Minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
sol = 5×1
1.0000 0.8534 -0.4176 4.5550 -5.3446
double(A)*sol - double(Z)
ans = 5×1
4.8257 -2.9487 2.6561 -1.1261 -0.7202
  2 Kommentare
DoinK
DoinK am 1 Nov. 2022
i'm sorry sir, but the sum of pi must equal to 1
so i think we cannot assume p1=1
can we use z (p1 value) to get all value of pi?
Torsten
Torsten am 1 Nov. 2022
syms p1 p2 p3 p4 p5 a
R =[1 2 3 1 2;4 5 1 2 6;7 1 2 1 2;1 4 3 2 2;1 5 4 3 2];
I =[1 0 0 0 0;0 1 0 0 0;0 0 1 0 0;0 0 0 1 0;0 0 0 0 1];
pi =[p1 p2 p3 p4 p5];
e =[1;1;1;1;1];
a=pi*(I-R)^(-1)*e
a = 
t=a - 1
t = 
z=solve(t,p1) %get p1
z = 
A_0=[2 1 1 2 4;1 2 2 1 1;2 2 1 1 3;1 3 6 2 2;1 3 4 1 2];
B =[1 3 2 1 2;2 1 2 7 1;1 2 1 2 3;1 4 2 1 2;2 3 1 2 2];
y=pi*(A_0+R*B)
y = 
j =subs(y,p1,z) %substitude p1 to 5 equations
j = 
[A,Z]=equationsToMatrix(j,pi)
A = 
Z = 
sol = lsqlin(double(A),double(Z),[],[],[1 1 1 1 1],1)
Minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
sol = 5×1
1.3539 0.8534 -0.4176 4.5550 -5.3446
double(A)*sol - double(Z)
ans = 5×1
4.8257 -2.9487 2.6561 -1.1261 -0.7202
sum(sol)
ans = 1.0000

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by