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

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.

댓글을 달려면 로그인하십시오.

 채택된 답변

darova
darova 2020년 5월 29일
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

태그

질문:

2020년 5월 29일

댓글:

2020년 5월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by