I want to know what causes error in my code using fsolve.....very much thanks in advance

1 次查看(过去 30 天)
%My function is following
function F = funhddtryone(X)
T2 = X(1);
T3 = X(2);
T4 = X(3);
T5 = X(4);
T6 = X(5);
% Known values
Acond = 3.5;
UL = 7.04;
a = 300;
Q = 10000;
Ucond = 47.9;
K = 0.0015;
cp = 4.193;
cpw = 4.193;
cpa = 1.009;
Ma = 0.028966;
Mw = 0.018016;
G = 0.040;
L = 0.015;
Hvap = 2332.20*1000;
P = 101.1*1000;
Tamb = 25+273;
T1 = 25+273;
A = 0.1225;
V = 0.0410375;
P0 = 7.384*1000;
A1 = 67.35;
B1 = -7218.15;
C1 = -7.9939;
D1 = 0.00052333;
E1 = L*cp*(T1 - T2) - A*UL*(T5/2 + T6/2 - Tamb) - G*(T5*cpa - T6*cpa + (Mw*P0*exp(A1 + B1/T5 + C1*log(T5) + D1*T5)*(Hvap + T5*cpw))/(Ma*(P - P0*exp(A1 + B1/T5 + C1*log(T5) + D1*T5))) - (Mw*P0*exp(A1 + B1/T6 + C1*log(T6) + D1*T6)*(Hvap + T6*cpw))/(Ma*(P - P0*exp(A1 + B1/T6 + C1*log(T6) + D1*T6))));
E2 = L*cp*(T2 - T1)-(Ucond*Acond*[(T6 - T2)-(T5 - T1)]/(log((T6 - T2)/(T5 - T1))));
E3 = G*(T5*cpa - T6*cpa + (Mw*P0*exp(A1 + B1/T5 + C1*log(T5) + D1*T5)*(Hvap + T5*cpw))/(Ma*(P - P0*exp(A1 + B1/T5 + C1*log(T5) + D1*T5))) - (Mw*P0*exp(A1 + B1/T6 + C1*log(T6) + D1*T6)*(Hvap + T6*cpw))/(Ma*(P - P0*exp(A1 + B1/T6 + C1*log(T6) + D1*T6)))) - A*UL*(T5/2 + T6/2 - Tamb) + L*cp*(T3 - T4);
E4 = - G*(T5*cpa - T6*cpa + (Mw*P0*exp(A1 + B1/T5 + C1*log(T5) + D1*T5)*(Hvap + T5*cpw))/(Ma*(P - P0*exp(A1 + B1/T5 + C1*log(T5) + D1*T5))) - (Mw*P0*exp(A1 + B1/T6 + C1*log(T6) + D1*T6)*(Hvap + T6*cpw))/(Ma*(P - P0*exp(A1 + B1/T6 + C1*log(T6) + D1*T6)))) - (K*V*a*(T3*cpa - T4*cpa + T5*cpa - T6*cpa + (Mw*P0*exp(A1 + B1/T3 + C1*log(T3) + D1*T3)*(Hvap + T3*cpw))/(Ma*(P - P0*exp(A1 + B1/T3 + C1*log(T3) + D1*T3))) - (Mw*P0*exp(A1 + B1/T4 + C1*log(T4) + D1*T4)*(Hvap + T4*cpw))/(Ma*(P - P0*exp(A1 + B1/T4 + C1*log(T4) + D1*T4))) + (Mw*P0*exp(A1 + B1/T5 + C1*log(T5) + D1*T5)*(Hvap + T5*cpw))/(Ma*(P - P0*exp(A1 + B1/T5 + C1*log(T5) + D1*T5))) - (Mw*P0*exp(A1 + B1/T6 + C1*log(T6) + D1*T6)*(Hvap + T6*cpw))/(Ma*(P - P0*exp(A1 + B1/T6 + C1*log(T6) + D1*T6)))))/log((T3*cpa - T6*cpa + (Mw*P0*exp(A1 + B1/T3 + C1*log(T3) + D1*T3)*(Hvap + T3*cpw))/(Ma*(P - P0*exp(A1 + B1/T3 + C1*log(T3) + D1*T3))) - (Mw*P0*exp(A1 + B1/T6 + C1*log(T6) + D1*T6)*(Hvap + T6*cpw))/(Ma*(P - P0*exp(A1 + B1/T6 + C1*log(T6) + D1*T6))))/(T4*cpa - T5*cpa + (Mw*P0*exp(A1 + B1/T4 + C1*log(T4) + D1*T4)*(Hvap + T4*cpw))/(Ma*(P - P0*exp(A1 + B1/T4 + C1*log(T4) + D1*T4))) - (Mw*P0*exp(A1 + B1/T5 + C1*log(T5) + D1*T5)*(Hvap + T5*cpw))/(Ma*(P - P0*exp(A1 + B1/T5 + C1*log(T5) + D1*T5)))));
E5 = Q - (L*cp*(T3 - T2));
F = [E1;E2;E3;E4;E5];
end
% fsolve code is following
clc
format short
X0 = [44.2;62.2;46.4;41.7;47.5];
options = optimset(options,'StepTolerance =1e-10 ');
FSol = abs(vpa(fsolve(@funhddtryone, X0,options)))
  4 个评论
darova
darova 2019-10-2
You have a lot of complicated functions and several equations
1212Untitled.png
Maybe you can explains where those equations come from? Or maybe they can be simplified?
hussain soomro
hussain soomro 2019-10-7
Dear Darova, I have to solve 5 non-linear equations with 5 unknowns, would you suggest any method? I have tried, fsolve, but it just gives error, any other way to solve this problem? Thanks

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2019-10-7
x = sym('x', [1 5]);
F = funhddtryone(x);
digits(16);
sol = vpasolve(F);
However, vpasolve() says that there is no solution.
Equations 1, 2, and 4 can be solved for x1, x2, x3 in ways that are not totally unreasonable. After substitution, that leaves two equations in x4 and x5, and solving those for closed form solutions is difficult or not possible.
It would be about that point that you would start graphing to determine whether any solution is feasible.

更多回答(1 个)

Raunak Gupta
Raunak Gupta 2019-10-4
Hi,
To check whether the solution exist with the giving starting point, MaxFunEvals and MaxIter have been set to a higher value so the solver terminate with some terminal condition met, that is either TolFun or TolX. The solver has stopped with TolX condition met that is the size of step is small enough to stop but the value of function of very high and thus No Solution Found.
options = optimset('TolFun',1e-10,'TolX',1e-5,'MaxFunEvals',5000,'MaxIter',1000);
You may refer to the steps mentioned in When the Solver Fails and fsolve Could Not Solve Equation for correcting the function definition or parameters in the optimization problem.
  1 个评论
hussain soomro
hussain soomro 2019-10-7
Dear Raunak Gupta, I have to solve 5 non-linear equations with 5 unknowns, would you suggest any method? I have tried, fsolve, but it just gives error, any other way to solve this problem? Thanks

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by