I was writing a dynamic model recently, but I ran into some problems that I couldn't solve.
The following is part of the code, the function I want to implement is that when Tb2
is less than the saturation temperature Tbaohe
, the logarithmic average temperature difference T1
is used to solve, and when Tb2
is equal to the saturation temperature, continue to use the arithmetic average temperature difference T2
on the basis of the above solution results to continue the solution, where Tc1
is equal to Tbaohe
.
Kc*Ac*T3 = (Wnjs + Gna)*(hc1 - hb2);
T1 = ((Te1 - Tbaohe) - (Tc1 - Tb2))/(ln((Te1 - Tbaohe)/(Tc1 - Tb2)));
T2 = (Te1 + Tbaohe)/2 - (Tc1 + Tb2)/2;
if Tb2 < Tbaohe then
T3 = T1;
else
T3 = T2;
end if;
But when I solve, I get the following error. Apparently there is a problem with the ln
function here, it seems that when Tb2
is infinitely close to the saturation temperature Tbaohe
, the run stops automatically, I can't fix this.
Error: The following error was detected at time: 10.86044238659505
Model error - division by zero: (Te1-Tbaohe) / (Tc1-Tb2) = (104.936) / (0)
First evaluation failed for non-linear solver.
First evaluation failed for non-linear solver.
Thanks in advance for your reply!
If the two temperatures become close, you are dividing by zero. Tb2 should not become larger than Tc1, otherwise you would get a negative value for the ln function. You could use max(1e-4, (Tc1 - Tb2)) instead of (Tc1 - Tb2). If Tb2 is intended to become larger than Tc1, than there might be an error in your equation. The complete source code would be helpful to identify variables and parameters.