MATLAB Answers

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

2 views (last 30 days)
hussain soomro on 1 Oct 2019
Answered: Walter Roberson on 7 Oct 2019
%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 CommentsShowHide 3 older comments
hussain soomro on 7 Oct 2019
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

Sign in to comment.

### Accepted Answer

Walter Roberson on 7 Oct 2019
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.
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### More Answers (1)

Raunak Gupta on 4 Oct 2019
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 CommentShowHide None
hussain soomro on 7 Oct 2019
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

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!