error in computing log values
27 次查看(过去 30 天)
显示 更早的评论
F SHEFIN
2021-12-2
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
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
F SHEFIN
2021-12-2
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....
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
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..
F SHEFIN
2021-12-2
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...
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
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
回答(1 个)
Mathieu NOE
2021-12-2
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
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
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
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).
F SHEFIN
2021-12-2
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....
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
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
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-6
Look at pg 91 sir..under CH4...for less than 1000 there will be constant values and for above 1000 there will be values
F SHEFIN
2021-12-6
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 General Applications 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)