Integration problem, getting wrong answer in matlab
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Alice Faisal
il 24 Lug 2018
Risposto: Giuseppe Infantino
il 8 Gen 2020
Good morning I have an integration that I need to compute, I used MATLAB but I did not get the right answer.
This is the integral:
exp(-(t-1)^2/(σ^2)) dt
from -Inf to Inf. I am getting that it equals zero which is impossible, can any one help me?
Thank you in advance
2 Commenti
Risposta accettata
Walter Roberson
il 24 Lug 2018
How are you doing the integration?
>> sigma = 7
sigma =
7
>> syms t
>> exp(-(t-1)^2/(sigma^2))
ans =
exp(-(t - 1)^2/49)
>> int(ans,t,-inf,inf)
ans =
7*pi^(1/2)
3 Commenti
Walter Roberson
il 24 Lug 2018
Your function only has measurable contribution between 0.999999999996143 1.00000000000386 . If you integral() specifying those as bounds, you will get a numeric solution.
Steven Lord
il 24 Lug 2018
Walter is correct. Let's record the values with which integral evaluated your integrand, to see where it "looked" for an "interesting" region of your integral. Run the attached file with two output arguments.
[result, T] = integrationExample;
result is 0. Look at the x variable in the table T. It did evaluate your integrand function at values close to x = 1, but not nearly close enough.
The problem is that g^2 is an EXTREMELY small number, so unless (x-1)^2 is also EXTREMELY small the product of (x-1)^2 and g^(-2) will be large. If that product is large enough computing the exponential of the negative of that product will underflow. Computing exp(-k) for k greater than about 740 underflows to 0.
Changing the limits of integration gets you something other than 0, but your function is only nonzero for an extremely small range of x and so the value of the integral, while positive, is still extremely small.
[result, T] = integrationExample([1-1e-10, 1+1e-10]);
result
plot(T.x, T.function_value, 'o-')
Più risposte (1)
Giuseppe Infantino
il 8 Gen 2020
Guys, I have incredible integration issues, see below:
I need to calculate a difficult integral and I didn't obtain good results, so I try a very simple integral in order to try to understand the problem and as you can see from the code below, Matlab provides a wrong results, beacuse the correct results is (-log(1-x)) and not (-log(x-1)), and for these reasons I'm having lots of troubles in my computations. Honestly, I have no idea about this problem, I even doubts about my capabilty of calculating such a simple integral so that I verify with WolphramAlpha that provides the correct results!
Could someone help me? Thank you very much and sorry for my english.
>>int (1./(1-x), x)
ans =
-log(x-1)
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!