フィルターのクリア

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 Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by