Closed a2468834 closed 5 years ago
Another example about infinite interval integral.
If f(x)=e^(-x^2), we could calculate the integral of f(x) over [-∞, ∞] by hands in advance.
To compute an integral over a infinite interval, you have to perform the change of variables x=t/(1-t²):
Now we could turn all of them into Julia script.
function f(x)
return exp(-x^2)
end
function g(t)
return f(t/(1-t^2))*(1+t^2)/((1-t^2)^2)
end
hquadrature(g, -1, 1)
returning (1.772453850905516, 2.95326836403382e-9) which are the same as our calculation by hands.
Duplicate of #32
Although there is a link introducing how to apply change of variables method to compute integrals over infinite or semi-infinite domains, I think taking an example would be more friendly way to explain how to use it.
To compute an integral over a semi-infinite interval, you have to perform the change of variables x=a+t/(1-t):
Now we could turn all of them into Julia script.
returning
(1.0, 1.1102230246251565e-14)
which are the same as our calculation by hands.