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 Comments

Show energy_balance function
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.

Sign in to comment.

 Accepted Answer

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

2 Comments

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

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2018b

Tags

Community Treasure Hunt

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

Start Hunting!