Numerical integration

2 views (last 30 days)
Abhishek Ghosh
Abhishek Ghosh on 9 Jun 2012
suppose i got a function of two variables and have to numerically integrate it over one of them within some specified limits. is there any functions which can handle this situation?
in this case the other variable is also a variable parameter i.e the solution function takes the second variable and the time range and the answer gets computed.
i found trapezoid fn. but is there anything else without the need for specifying intervals?
  1 Comment
Sargondjani
Sargondjani on 9 Jun 2012
what do you mean with "without the need to specify the interval"? you mean you want it from -inf to inf??
there are many other ways to calculate it, search for 'quadrature'. it depends on the functional form which method is best suited... i know 'quad' of matlab uses simpsons rule, and there might be more built in function (check also the file exchange)

Sign in to comment.

Accepted Answer

Abhishek Ghosh
Abhishek Ghosh on 10 Jun 2012
guys, thanks for the reply.
In my case there is no function to call, there are just experimental data points to be integrated; arrays to say and I found trapz to be best suited for such an application

More Answers (2)

Julius
Julius on 9 Jun 2012
I suggest to use the Gauss quadrature...For example this function: http://www.mathworks.com/matlabcentral/fileexchange/4540-legendre-gauss-quadrature-weights-and-nodes to generate the integration points and the weighting coefficients for your intervals(a,b). Then solve the integral using the summation:
[x,w]=lgwt(N,a,b)
YourIntegral=0;
for i=1:N
syms y z
YourFunction=subs(y^2-4*z,{y, z},[x(i),x(i)]);
YourFunction=double(YourFunction);
YourIntegral=YourIntegral+YourFunction*w(i)*w(i);
end
YourIntegral
This is the integration in a symbolic way. You can change the function y^2-4*z to whichever you want. Or simply use the quad function from Matlab:
F = @y^2-4*z;
Q = quad(F,a,b);

Mike Hosea
Mike Hosea on 10 Jun 2012
If I understand the question properly, given a function f(x,y) and integration limits a <= x <= b,
g = @(y)integral(@(x)f(x,y),a,b)
produces a function g that you can do what you want with. The limits a and b may be functions that depend on y if you like. If your version of MATLAB is older than R2012a, use QUADGK instead of INTEGRAL. -- Mike

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!