You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
error in computing log values
33 views (last 30 days)
Show older comments
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 Comments
Walter Roberson
on 2 Dec 2021
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
on 2 Dec 2021
I see log() mentioned in your title. So track down why you are trying to take log of a negative number.
F SHEFIN
on 2 Dec 2021
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)
This is the error which i get initially...
when i covert all the log terms..like log(complex(x))....then i get a signal mismatch
Walter Roberson
on 2 Dec 2021
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
on 2 Dec 2021
Edited: Walter Roberson
on 2 Dec 2021
function [h1,h2,h3,h4,h5] = OutletEnthalpy(Tad)
CH4 = 0;
N2 = 0;
O2 = 0;
CO2 = 0;
H2O = 0;
if Tad < 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);
else
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); %HERE
end
h1 = CH4;
Here i get error in the bolded line...my simulation stops at this line...for certain values of input..
Walter Roberson
on 2 Dec 2021
My prediciton:
Tad is a vector rather than a scalar. And it has values that are both < 1000 and >= 1000.
Walter Roberson
on 2 Dec 2021
Simulink models can be attached to posts here using the paperclip icon of the editor.
F SHEFIN
on 2 Dec 2021
Sir...i have attached the model..
there are 4 inputs..actualyy...T,Ratio,Fuel,Per the output is next to the solver...
pls keep T as 100 at every trail.
For all values of Ratio @ 1 per i am getting my answer..
When ratio changes to 1 simulink doesnt compute @ 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9 ...but computes @ 1 per
when ratio changes ti 2 , simulink doesnt compute @ 0.3 to 0.9....but computes @ 0.1, 0.2,1 per.
similarly for ratio 3 and 4 some values are alone getting computed,
But when ratio is 5 i am able to compute @ all the per values.
It is not simulating for some values...i hope i was clear withe the problem. Thank you
Answers (1)
Mathieu NOE
on 2 Dec 2021
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 Comments
F SHEFIN
on 2 Dec 2021
Sir...the function of the solver is to give a value at which the values of P and R are equal.That value at which P = R is my answer(output)(tad) sir. Now when i am adding a memory block...i am getting the input as my final answer. But the simulation is running...can u suggest any other to overcome this error without disturbing the function of the solver.
Mathieu NOE
on 2 Dec 2021
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
on 2 Dec 2021
Sir pls..Check the value of Per...@ 1 as value of Per...you will not see that big positive error...whereas when you reduce per to 0.9,0.8...upto 0.1 you will see that error. it gives a positive value due to the change in mole values(N1,N2,N3,N4,N5).
Mathieu NOE
on 2 Dec 2021
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
on 2 Dec 2021
Yes Sir...but the two formulas are same , only the values of variables alone change....So i assume that the trend of graph depends on the initial input and predefined values...I am not able to decode the discontinuities reason....
Mathieu NOE
on 3 Dec 2021
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 ...
Mathieu NOE
on 6 Dec 2021
hello
would it be possible to share some info from this handbook ?
F SHEFIN
on 6 Dec 2021
Sir @Mathieu NOE Tq for ur patient help...i got the reason for the discontinuity..its because the coefficient values should be same in both the user defined functions..i.e (InletEnthalpy and OutletEnthalpy),they were not same, so we got the error..Now after changing...its perfectly working...Thank you for your help. And @Walter Roberson Tq for your initial suggestions.
Mathieu NOE
on 6 Dec 2021
Congrats !
glad you found the bug...
it's chrismas already !
all the best
See Also
Categories
Find more on General Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)