How to solve multiple equation and get all value of the variable?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
DoinK
el 1 de Nov. de 2022
Comentada: Torsten
el 1 de Nov. de 2022
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?
0 comentarios
Respuesta aceptada
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
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 = lsqlin(double(A),double(Z),[],[],[1 0 0 0 0],1)
double(A)*sol - double(Z)
2 comentarios
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
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 = lsqlin(double(A),double(Z),[],[],[1 1 1 1 1],1)
double(A)*sol - double(Z)
sum(sol)
Más respuestas (0)
Ver también
Categorías
Más información sobre Calculus en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!