How I solve a nonlinear equation with matlab function block?
1 view (last 30 days)
Show older comments
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?
Accepted Answer
Ameer Hamza
on 4 Sep 2020
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 Comments
More Answers (0)
See Also
Categories
Find more on Sources in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!