How I solve a nonlinear equation with matlab function block?

Here is my blocks and 'Generator' matlab function block contents is
function StrongSolution = Generator(HotWater,WeakSolution, CoolingCapacity)
P = 4.82 % [kPa], Absolute Pressure
Cp = 4.2 % kJ/kgK
T_in = HotWater(1) % Celious
T_out = HotWater(2) % Celious
m_w = HotWater(3) % kg/s
T_w = WeakSolution(1) % Celious
x_w = WeakSolution(2)/100 % Nondimension
m_w = WeakSolution(3) * CoolingCapacity % kg/s
h_w = WeakSolution(4) % kJ/kg
WasteHeat = m_w*Cp*(T_in - T_out) % kJ
Tacc = 88
UA_G = 16.6*CoolingCapacity/(0.0986*exp(0.0254*Tacc))
T_lmG = WasteHeat/UA_G
fun = @(T_s) T_lmG - ((T_out-T_w)-(T_in-T_s))/log((T_out-T_w)/(T_in-T_s))
T_s = fzero(fun,[55 100])
StrongSolution = T_s
end
And I upload my problem.
I wanted to know 'T_s'. So I used 'fzero' function in a Matlab function block.
But the error was occured.
How can I solve the problem?

 채택된 답변

Ameer Hamza
Ameer Hamza 2020년 9월 4일
The current problem should be fixed by putting a semicolon (;) at the end of line 21 of your code
fun = @(T_s) T_lmG - ((T_out-T_w)-(T_in-T_s))/log((T_out-T_w)/(T_in-T_s));
But then another error occurs, which is unrelated to the current error. It is caused by negative values inside the log() during the execution of fzero(). You may need to adjust the interval for the solution or input parameters to see how you can avoid creating negative input to log() function.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Model Predictive Control Toolbox에 대해 자세히 알아보기

제품

질문:

2020년 9월 4일

답변:

2020년 9월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by