How do I solve this System of equations

1 回表示 (過去 30 日間)
Armin Narimanzadeh
Armin Narimanzadeh 2019 年 5 月 27 日
編集済み: Star Strider 2019 年 5 月 27 日
I have this system of equation which I am trying to solve with no avial:
(1) Qs-Qcond=7500
(2) Qs-(2777*ms)/3.6=0
(3) ms*2777-ms*hcond=27000
(4) Qcond-ms*hcond/3.6=0
I tried to substitue equation 4 into 3 to get a 3 equation 3 unknown problem. Tried the matrix approach it seems that the matrix created is singular, therefore, no answer. I guess I need one more equation for this, just wanted someone else to check as well since I might be blind to something here.
the code that I wrote is as such:
Steam_enthalpy=2777.7
Q_brine_heater_power=7500
P=zeros(3,3);
P(1,1)=1;
P(1,2)=-Steam_enthalpy./3.6;
P(1,3)=0;
P(2,1)=1;
P(2,2)=0;
P(2,3)=-1;
P(3,1)=0;
P(3,2)=Steam_enthalpy;
P(3,3)=-3.6;
PP=inv(P);
O=[0;Q_brine_heater_power; 3.6.*Q_brine_heater_power];
ZZ=PP*O;
Steam_power(1,i)=ZZ(1,1); %this is Qs
Steam_mdot(1,i)=ZZ(2,1); %This is ms
condensate_power(1,i)=ZZ(3,1); %This is Qcond

回答 (2 件)

John D'Errico
John D'Errico 2019 年 5 月 27 日
編集済み: John D'Errico 2019 年 5 月 27 日
You are trying to do this with paper and pencil?
syms Qs Qcond ms hcond
E(1) = Qs-Qcond == 7500;
E(2) = Qs-(2777*ms)/3.6 == 0;
E(3) = ms*2777-ms*hcond == 27000;
E(4) = Qcond-ms*hcond/3.6 == 0;
vars = solve(E)
vars = solve(E)
vars =
struct with fields:
Qcond: [1×1 sym]
Qs: [1×1 sym]
hcond: [1×1 sym]
ms: [1×1 sym]
>> vars.Qs
ans =
13885/18
>> vars.Qcond
ans =
-121115/18
>> vars.ms
ans =
1
>> vars.hcond
ans =
-24223
etc.
If you want to solve it using linear algebra, then you need to remember that this is not a linear problem. You have products of variables in there.
You can MAKE it linear, by a simple transformation. That is,
T = ms*hcond
Then your equations become:
Qs - Qcond = 7500;
Qs - (2777*ms)/3.6 = 0;
ms*2777 - T = 27000
Qcond - T/3.6 = 0;
This system is linear in the unknowns.
But don't use INV!!!!!!!!!!!! Use backslash. But FIRST, you might decide to check to see if the system is solvable. If the rank of M is less than 4, then you have a problem.
M = zeros(4,4);
rhs = [7500 ; 0 ; 27000 ; 0];
M(1,[1 2]) = [1 -1];
M(2,[1 3]) = [1 -2777/3.6];
M(3,[3 4]) = [2777 -1];
M(4,[2 4]) = [1 -1/3.6];
rank(M)
ans =
3
Since M is singular, the problem is NOT solvable using inv. Time for you to return to linear algebra 101. If you never took that class, then since you are solving linear systems of equations, why not?
Sigh. The problem is still solvable, using other methods. INV does NOT apply here!!!!!!!!!!! No inverse for this matrix exists. It is SINGULAR.
rank(M)
ans =
3
rank([M,rhs])
ans =
3
Since the rank of M is the same as the rank of M when it is appended with the right hand side vector, then the linear system has a solution, even though it is not full rank. Since the two ranks are the same, that means we can write the right hand side as a linear combination of the solumns of M. A solution does indeed exist. This is why solve succeeded. A solution does indeed exist. But it is not unique.
vars2 = pinv(M)*rhs
vars2 =
6998.66231539759
-501.337684602362
9.07280674664572
-1804.8156645685
double(vars.Qs)
ans =
771.388888888889
So even though pinv and solve both give valid solutions for Qs here, they are not the same.
Qs = vars2(1)
Qcond = vars2(2)
ms = vars2(3)
T = vars2(4)
hcond = T/ms
Qs =
6998.66231539759
Qcond =
-501.337684602362
ms =
9.07280674664572
T =
-1804.8156645685
hcond =
-198.925835738291
Again, the solution is NOT unique! Your system of equations is singular, with infinitely many solutions.
The complete solution to the linear system is given as:
pinv(M)*rhs + s*null(M)
where null(M) is the nullspace of the matrix M.
null(M)
ans =
0.25854383047555
0.258543830475532
0.000335166650958587
0.930757789711902
So I can add any amount of that vector to any valid solution, and it will still be a solution.
  2 件のコメント
Armin Narimanzadeh
Armin Narimanzadeh 2019 年 5 月 27 日
Thanks for this. did you try this yourself in MATLAB? My Matlab does not have this math toolbox so I can't try this. Thats why I tried Inverse matrix setup but it didn't work.
John D'Errico
John D'Errico 2019 年 5 月 27 日
I had not finished writing my moderately lengthy response. So my answer shows two ways to solve it.
You need to learn about how to...
  • recognize a singular matrix
  • determine if a solution exists anyway
  • solve a singular system to find that solution

サインインしてコメントする。


Star Strider
Star Strider 2019 年 5 月 27 日
編集済み: Star Strider 2019 年 5 月 27 日
If you have the Optimization Toolbox, you can use fsolve:
% % % b = [hcond ms Qs Qcond]
A = @(b) [b(3)-b(4)-7500; b(3)-2777*b(2)/3.6; b(2)*2777-b(1).*b(2)-27000; b(4)-b(1).*b(2)/3.6];
B = fsolve(A, ones(4,1))
producing:
B =
-1710.35074978887
6.01691320903996
4641.37999486221
-2858.62000513779
So B(1) = hcond, B(2) = ms, B(3) = Qs, and B(4) = Qcond.
I get different results from the Symbolic Math Toolbox code, however this is most likely the result of solver differences. My‘ ‘A’ function is coded correctly.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by