How to find 开发者_StackOverflow社区integrals from limits -infinity to +infinity in SCILAB ? ( Expression to be integrated are not directly integratable )
Change the variable of integration from x=(-inf,inf) to z=atan(x)
x=tan(z),
dx/dz = 1/(cos(z))^2
In the new variable z, the integration limits are from -%pi/2+eps to +%pi/2-eps, where eps is a very small positive number (else you will not be able to divide by the cos(z)) and
integral f(x) dx =
= integral f(x(z)) d(x(z))
= integral f(z) dx/dz dz
For example,
function y=Gaussian(x); y=exp(-x^2/2)/sqrt(2*%pi); endfunction;
intg(-10,10,Gaussian)
The same integration result is achieved with
function y=Gmodified(z); x=tan(z); y=Gaussian(x)/(cos(z))^2; endfunction;
intg(atan(-10),atan(10),Gmodified)
Interestingly, Scilab will take the above integral even for
intg(-%pi/2,%pi/2,Gmodified)
but this is only because Scilab evaluates 1/cos(%pi/2) as 1.633D+16 rather than infinity.
精彩评论