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 Commenti

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?
I see log() mentioned in your title. So track down why you are trying to take log of a negative number.
Yes sir i do have a Log
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
Log is being taken for a positive number sir...I run the values through a algebraic constant solver....i am not sure where the value turns out to be negative for log....
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
F SHEFIN il 2 Dic 2021
Modificato: Walter Roberson il 2 Dic 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..
Yes sir it is a matlab function Block.....if possible can we connect on a call...it will be easy for me explain...or else suggest me a way to communicate my whole model to you...
My prediciton:
Tad is a vector rather than a scalar. And it has values that are both < 1000 and >= 1000.
Simulink models can be attached to posts here using the paperclip icon of the editor.
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

Accedi per commentare.

Risposte (1)

Mathieu NOE
Mathieu NOE il 2 Dic 2021

0 voti

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 Commenti

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.
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)
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).
I think the presence of memory block can be avoided..coz..it will step back and give the input value as our answer. It disturbs the function of solver....
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
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....
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 ...
Hello sir..Those are constant values sir..from NASA handbook..
hello
would it be possible to share some info from this handbook ?
Look at pg 91 sir..under CH4...for less than 1000 there will be constant values and for above 1000 there will be values
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.
Congrats !
glad you found the bug...
it's chrismas already !
all the best
Thank you sir....Merry Christmas

Accedi per commentare.

Richiesto:

il 2 Dic 2021

Commentato:

il 6 Dic 2021

Community Treasure Hunt

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

Start Hunting!

Translated by