error in computing log values
显示 更早的评论
Hi sir..My simulink model runs Good for certain values of input...but for some values it gives a complex computation error.I have used a algebraic constraint solver.
An error occurred while running the simulation and the simulation was terminated
Caused by:
- Domain error. To compute complex results from real x, use 'log(complex(x))'.
- Error in log.m (line 14) coder.internal.error('Coder:toolbox:ElFunDomainError',mfilename); Error in 'ExitMoles/OutletEnthalpy' (line 20)
11 个评论
Walter Roberson
2021-12-2
Either change everything downstream to expect complex, or else figure out how the signal is going complex. Do you have sqrt() of something, or log() of something, or something to a power?
Walter Roberson
2021-12-2
I see log() mentioned in your title. So track down why you are trying to take log of a negative number.
F SHEFIN
2021-12-2
F SHEFIN
2021-12-2
F SHEFIN
2021-12-2
Walter Roberson
2021-12-2
We need to see the ExitMoles/OutletEnthalpy block. Is it a MATLAB Function Block? Is it a Mathematical Function Block ?
We will not be able to resolve this for you without seeing more of how the value is being computed that you are trying to take the log of.
F SHEFIN
2021-12-2
编辑:Walter Roberson
2021-12-2
F SHEFIN
2021-12-2
Walter Roberson
2021-12-2
My prediciton:
Tad is a vector rather than a scalar. And it has values that are both < 1000 and >= 1000.
Walter Roberson
2021-12-2
Simulink models can be attached to posts here using the paperclip icon of the editor.
F SHEFIN
2021-12-2
回答(1 个)
Mathieu NOE
2021-12-2
0 个投票
hello
the "log" error was just a consequence of an algebraic loop of OutletEnthalpy bloc : (its input is dependant of the P output)
so probably log of zero or NaN or negative Tad would trigger the error.
simply added a memory block on the P input signal of the OutletEnthalpy bloc and seems the simulation runs fine now (as far I can tell)

13 个评论
F SHEFIN
2021-12-2
Mathieu NOE
2021-12-2
ok - i didn't pay too much attention to this point
so I did a few manual checks to see if the solver would have a chance to find the solution
so I put a constant Tad input to the OutletEnthalpy block and looked at the error (P - R)
I had to go very high with Tad to see a start of reduction of the (negative) error
at Tad = 990 I still have a large negative error

at Tad = 1000, the error jumps to a very big positive error

so there must be a discontinuity in the simulation that prevents the solver to find the solution
the question is why the OutletEnthalpy block would jump from large negative to large positive P values when Tad crosses the threshold (1000)
F SHEFIN
2021-12-2
F SHEFIN
2021-12-2
Mathieu NOE
2021-12-2
ok I removed the memory block
the simulation seems to work for a few Per values (either low 0 to 0.2 ) or high (0.9 and 1)
In between those two areas we get an error
now I wanted to test the continuity of the laws that are coded in the OutletEnthalpy block
if I look at the first equations for CH4 and plot it for the two case (Tad<1000 or >=1000) , there is a significant discontinuity at tad = 1000 - and that worries me. Shouldn't be the two laws coincident at Tad = 1000 ?

% test CH4
Tad = 1:10:1000;
% CH4
a1ch4 = -1.7669e+05;
a2ch4 = 2.7862e+03;
a3ch4 = -12.0258;
a4ch4 = 0.0392;
a5ch4 = -3.6191e-05;
a6ch4 = 2.0269e-08;
a7ch4 = -4.9767e-12;
b1ch4 = -2.3313e+04;
b2ch4 = 89.0432; %#ok<NASGU>
% H of CH4
CH4 = (((-a1ch4)./Tad.^2)+((a2ch4*log(Tad))./Tad)+a3ch4+((a4ch4*Tad)/2)+((a5ch4*Tad.^2)/3)+((a6ch4*Tad.^3)/4)+((a7ch4*Tad.^4)/5)+(b1ch4./Tad)).*(8.31.*Tad);
plot(Tad,CH4);hold on
Tad = 1001:10:2000;
a1ch4 = 3730042.76000000;
a2ch4 = 1034972.09600000;
a3ch4 = -2412.69856200000;
a4ch4 = 4.64611078000000;
a5ch4 = 0.00229199830700000;
a6ch4 = -6.83683048000000e-07;
a7ch4 = 9.42646893000000e-11;
b1ch4 = -4.82238053000000e-15;
b2ch4 = -121.912488900000; %#ok<NASGU>
% H of CH4
CH4 = (((-a1ch4)./Tad.^2)+((a2ch4*log(Tad))./Tad)+a3ch4+((a4ch4.*Tad)/2)+((a5ch4*Tad.^2)/3)+((a6ch4*Tad.^3)/4)+((a7ch4*Tad.^4)/5)+(b1ch4./Tad)).*(8.31.*Tad);
plot(Tad,CH4);hold off
F SHEFIN
2021-12-2
Mathieu NOE
2021-12-3
hello again
yes I see the equation is the same and the constants are completely different - I'm very surprised ....
may I ask where did you find those values ? publication ? just curious ...
F SHEFIN
2021-12-5
Mathieu NOE
2021-12-6
hello
would it be possible to share some info from this handbook ?
F SHEFIN
2021-12-6
F SHEFIN
2021-12-6
Mathieu NOE
2021-12-6
Congrats !
glad you found the bug...
it's chrismas already !
all the best
F SHEFIN
2021-12-6
类别
在 帮助中心 和 File Exchange 中查找有关 Subsystems 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!