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

1 visualización (últimos 30 días)
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);
  1 comentario
Hossam Sayed
Hossam Sayed el 13 de Abr. de 2021
Editada: Hossam Sayed el 13 de Abr. de 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]);

Iniciar sesión para comentar.

Respuestas (2)

Matt J
Matt J el 13 de Abr. de 2021
Editada: Matt J el 13 de Abr. de 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
Walter Roberson el 13 de Abr. de 2021
Editada: Walter Roberson el 13 de Abr. de 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.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by