Faster Numerical Integral implementation
21 views (last 30 days)
Show older comments
I'm writing a program for finding the min of GMM. However, there is a lot of numerical integration in my GMM function and that's slowing my program down. I tried to write my own integration function using the Simpson's method. However, the values aren't very accurate compared with matlab's builtin integral function. I'm wondering what method does the builtin integral function use. Maybe there is a faster way to implement it? Thanks!
0 Comments
Answers (2)
Walter Roberson
on 5 Oct 2013
The different routines have different strengths. For example some of them cannot infinite range and others can. Some of them cannot handle a singularity at all and others can in some conditions.
The numeric integration routines are not able to analyze the function being integrated: they can only sample the outputs at particular locations and try to make guesses from there. The symbolic integration routines (Symbolic Toolbox) are able to examine the function to better figure out where the limitations might lie.
Does the function to be integrated have a closed form integral? If so then if you have access to the symbolic toolbox, do the symbolic integration once and use matlabFunction() to convert the result to an anonymous function that can be evaluated numerically.
Some numeric integration routines can work better if they have access to the gradient, so you could pre-calculate the gradient function and supply that to integration.
Meysam Mahooti
on 27 Nov 2019
Edited: Meysam Mahooti
on 5 Dec 2019
You can use my Runge-Kutta_Fehlberg(RKF78) implementation which is faster and more accurate than MATLAB ODE45 function.
Moreover, you can use my Radau||A implementation for fast and precise numerical integration.
options = rdpset('RelTol',1e-13,'AbsTol',1e-16);
% options: numerical error tolerance
[t,yout] = radau(@Accel,(0:Step:N_Step*Step),Y0,options);
% @Accel: function handle
% (0:Step:N_Step*Step): time span of integration
% Y0: Initial Values
0 Comments
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!