Numerical integration
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Sargondjani
am 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)
Akzeptierte Antwort
Weitere Antworten (2)
Julius
am 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);
0 Kommentare
Mike Hosea
am 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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!