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 件のコメント

darova
darova 2020 年 5 月 29 日
Show energy_balance function
Giorgio Ceresoli
Giorgio Ceresoli 2020 年 5 月 29 日
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));
Giorgio Ceresoli
Giorgio Ceresoli 2020 年 5 月 29 日
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 日

0 投票

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

2 件のコメント

Giorgio Ceresoli
Giorgio Ceresoli 2020 年 5 月 29 日
thanks!
Giorgio Ceresoli
Giorgio Ceresoli 2020 年 5 月 29 日
I put 'Real', true in the solve input.
it should return just one value being a third grade equation

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSymbolic Math Toolbox についてさらに検索

製品

リリース

R2018b

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by