필터 지우기
필터 지우기

Numerical integration

조회 수: 2 (최근 30일)
Abhishek Ghosh
Abhishek Ghosh 2012년 6월 9일
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
Sargondjani
Sargondjani 2012년 6월 9일
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)

댓글을 달려면 로그인하십시오.

채택된 답변

Abhishek Ghosh
Abhishek Ghosh 2012년 6월 10일
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

추가 답변 (2개)

Julius
Julius 2012년 6월 9일
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 2012년 6월 10일
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

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by