From: vlajchek on 16 Jun 2010 13:39 hello, I have a problem with the use of quad function in Matlab for numerical integration. Let me try to explain on an example. When I want to find the integral of expression exp(-x^2/2) from 0 to infinity, where for the higher limit I use some very large number: Q = quad('exp(-x.^2./2)',0,10000000000) I get the correct result sqrt(pi/2)=1.2533. If I try to use the same logic for the expression x*exp(-x^2/2) for the same limits: Q = quad('x.*exp(-x.^2./2)',0,10000000000) I get the result 0, although I know that correct result for this integral is 1. What can potentialy be the problem? The thing is I am solving some more difficult integrals, without analytical solutions, but in some way similar to this example, and I always get 0 where I don't expect it using the quad function. Thank you in advance...
From: Steven Lord on 16 Jun 2010 17:59 "vlajchek" <v_despotovic(a)yahoo.com> wrote in message news:2106186614.357396.1276724379296.JavaMail.root(a)gallium.mathforum.org... > hello, > > I have a problem with the use of quad function in Matlab for numerical > integration. Let me try to explain on an example. When I want to find the > integral of expression exp(-x^2/2) from 0 to infinity, where for the > higher limit I use some very large number: > > Q = quad('exp(-x.^2./2)',0,10000000000) > > I get the correct result sqrt(pi/2)=1.2533. > If I try to use the same logic for the expression x*exp(-x^2/2) for the > same limits: > > Q = quad('x.*exp(-x.^2./2)',0,10000000000) > > I get the result 0, although I know that correct result for this integral > is 1. > > What can potentialy be the problem? The thing is I am solving some more > difficult integrals, without analytical solutions, but in some way similar > to this example, and I always get 0 where I don't expect it using the quad > function. http://www.mathworks.com/matlabcentral/newsreader/view_thread/122969#310160 http://www.mathworks.com/matlabcentral/newsreader/view_thread/246456 Choose a _smaller_ interval (but one that still covers the whole region where your function is "interesting") over which to integrate the function. When I evaluate your integrand at x = 30, the answer is on the order of 1e-194 so that's probably good enough; if you want the integrand to be exactly 0 in double precision, use 50 as your upper limit instead. There's no need to use as large an upper limit as you did. quad(@(x) x.*exp(-x.^2/2), 0, 50) -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
From: vlajchek on 17 Jun 2010 08:41 Thanks Steve, it is still not easy to find a good interval of integration for the integrals I have to solve, but it's a good starting point
|
Pages: 1 Prev: free disk space on network drive Next: shift x coordinate for all x automatic? |