필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
DoinK
DoinK 2022년 11월 1일
댓글: Torsten 2022년 11월 1일
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?

채택된 답변

Torsten
Torsten 2022년 11월 1일
편집: Torsten 2022년 11월 1일
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
DoinK
DoinK 2022년 11월 1일
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 2022년 11월 1일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by