# FSOLVE requires all values returned by functions to be of data type double.

3 views (last 30 days)
Hossam Sayed on 13 Apr 2021
Edited: Walter Roberson on 13 Apr 2021
syms a b c d e
X=input('numb of carbon atoms in fuel');
Y=input('numb of hidrogen atoms in fuel');
Z=input('fuel to air ratio');
P=input('the pressure is in atm');
T=5000;
k1= (-2*(10^-19))*T^6 + (4*(10^-15))*T^5 - (3*(10^-11))*T^4 + (1*(10^-07))*T^3 - 0.0003*T^2 + 0.3206*T - 162.97;
k2= (2*(10^-19))*T^6 + (4*(10^-15))*T^5 - (4*(10^-11))*T^4 + (1*(10^-07))*T^3 - 0.0003*T^2 + 0.3749*T - 186.4;
K1=exp(k1);
K2=exp(k2);
V=[a,b,c,d,e];
F=@(V)[X*Z-V(2)-V(1);Z*Y/2-V(3)-V(2);(X+Y/4)*2-2*a-b-2*V(5)-V(3);V(4)*V(5)^0.5*P^0.5/(K1*(V(1)+V(2)+V(3)+V(4)+V(5)+3.76*(X+Y/4))^0.5)-V(3);V(2)*V(5)^0.5*P^0.5/(K1*(V(1)+V(2)+V(3)+V(4)+V(5)+3.76*(X+Y/4))^0.5)-V(1)];
[a,b,c,d,e]=fsolve(F,[0;0;0;0;0]);
disp(a);
Hossam Sayed on 13 Apr 2021
the error in command window
Error using fsolve (line 269)
FSOLVE requires all values returned by functions to be of data type double.
Error in qqq (line 18)
[a,b,c,d,e]=fsolve(F,[0;0;0;0;0]);

VBBV on 13 Apr 2021
%f true
[a,b,c,d,e]=fsolve(F,[0 0 0 0 0])
Try this
Hossam Sayed on 13 Apr 2021
still have the same error
FSOLVE requires all values returned by functions to be of data type double.
Error in qqq (line 18)
[a,b,c,d,e]=fsolve(F,[0 0 0 0 0]);

Matt J on 13 Apr 2021
Edited: Matt J on 13 Apr 2021
Get rid of
syms a b c d e
Write your equations in terms of the numeric variables V(i) instead. Do not use syms anywhere.

Walter Roberson on 13 Apr 2021
Edited: Walter Roberson on 13 Apr 2021
syms a b c d e
X=input('numb of carbon atoms in fuel');
Y=input('numb of hidrogen atoms in fuel');
Z=input('fuel to air ratio');
P=input('the pressure is in atm');
T=5000;
k1= (-2*(10^-19))*T^6 + (4*(10^-15))*T^5 - (3*(10^-11))*T^4 + (1*(10^-07))*T^3 - 0.0003*T^2 + 0.3206*T - 162.97;
k2= (2*(10^-19))*T^6 + (4*(10^-15))*T^5 - (4*(10^-11))*T^4 + (1*(10^-07))*T^3 - 0.0003*T^2 + 0.3749*T - 186.4;
K1=exp(k1);
K2=exp(k2);
V=[a,b,c,d,e];
Fsym = [X*Z-V(2)-V(1);Z*Y/2-V(3)-V(2);(X+Y/4)*2-2*a-b-2*V(5)-V(3);V(4)*V(5)^0.5*P^0.5/(K1*(V(1)+V(2)+V(3)+V(4)+V(5)+3.76*(X+Y/4))^0.5)-V(3);V(2)*V(5)^0.5*P^0.5/(K1*(V(1)+V(2)+V(3)+V(4)+V(5)+3.76*(X+Y/4))^0.5)-V(1)];
F = matlabFunction(Fsym, 'vars', {V});
[a,b,c,d,e]=fsolve(F,[0;0;0;0;0]);
disp(a);
However it is not at all clear why you would mix V(index) and explicit a, b, etc. in the expression if they are intended to be the same thing. If they are not intended to be the same thing, then you would have the unresolved variables a, b, c, d, e, and you would need to attempt to find symbolic solutions. MATLAB is not able to solve that symbolically; Maple is able to rewrite it as a polynomial in degree 6, with coefficients up to 10^7500 or so.
T=5000;
k1= (-2*(10^-19))*T^6 + (4*(10^-15))*T^5 - (3*(10^-11))*T^4 + (1*(10^-07))*T^3 - 0.0003*T^2 + 0.3206*T - 162.97;
with T that large, k1 is about -2935 and k2 is about -2687. And then you take exp() of those. In double precision, you just get 0 from the exp(). You need to switch to using T = sym(5000) to get non-zero K1 and K2.
Effectively if you could get results, they would be numeric garbage unless you evaluated at around 10000 digits. And then they wouldn't be garbage... they would just be useless, as terms such as 3.379827590*10^7653*P^2*Y^2*Z^2*a hint that your a, b, c, d, e would have to be on the order of 10^-7500, which is just not physical.