Numerical integration
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Sargondjani
il 9 Giu 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)
Risposta accettata
Più risposte (2)
Julius
il 9 Giu 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 Commenti
Mike Hosea
il 10 Giu 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 Commenti
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!