How to solve multiple equation and get all value of the variable?
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
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
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 件のコメント
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
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)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!