Why does solve function return an empty value in a for cycle?

for i=1:N
syms Tout
sol=solve (energy_balance,Tout,'Real',true, 'IgnoreAnalyticConstraints',true);
T_gp_out(i)=double(sol);
end
Solve function returns an empty value at the second iteration of the for cycle which i am using.
When the solve function is run separately outside the for cycle it returns a real value.
I can't understand what is going wrong when all inputs and syntax are correct.
Should I define a syms vector function outside the for cycle?
Can someone help me?
Thanks in advance.
Giorgio Ceresoli

3 个评论

energy_balance= Q_rad(i)+Q_conv(i)+n_CO2_in*h_CO2_in+n_CaO_in*h_CaO_in+n_CaCO3_in*h_CaCO3_in == n_CO2_out*(h_f_CO2+a_CO2*(Tout-T_ref)+b_CO2/2*(Tout^2-T_ref^2)+c_CO2/3*(Tout^3-T_ref^3))+n_CaO_out*(h_f_CaO+a_CaO*(Tout-T_ref)+b_CaO/2*(Tout^2-T_ref^2)+c_CaO/3*(Tout^3-T_ref^3))+n_CaCO3_out*(h_f_CaCO3+a_CaCO3*(Tout-T_ref)+b_CaCO3/2*(Tout^2-T_ref^2)+c_CaCO3/3*(Tout^3-T_ref^3));
all variables defined in energy balance equation are changed at every iteration.
during the second iteration the inputs values are saved in the workspace.
the problem is at output of solve, it seems like that there is no real solution.

请先登录,再进行评论。

 采纳的回答

You have cubic equation
It means that you have 3 roots
try
T_gp_out(i)=double(sol(1)); % choose first root

2 个评论

I put 'Real', true in the solve input.
it should return just one value being a third grade equation

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

产品

版本

R2018b

标签

Community Treasure Hunt

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

Start Hunting!

Translated by