Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Torsten
Torsten el 1 de Nov. de 2022
Editada: Torsten el 1 de Nov. de 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 comentarios
DoinK
DoinK el 1 de Nov. de 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 el 1 de Nov. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by