Numerically Integrating an Array
이전 댓글 표시
I have often integrated a function by using quad and dblquad. When using quad and dblquad, I can increase the tolerance parameter to the function to make sure that the answer is converging.
Instead of integrating a function, I need to now integrate an array. I know trapz can be used to do this. A simple example of this would be: t = linspace(0,10) y = cos(t) trapz(t,y)
However is there any way to adjust the tolerance or some other parameters, so that I can make sure that the answer is converging? If there is not any way to do this using the "trapz" function, is there another function you would recommend instead for numerically integrating the array?
Thank you, Kevin
P.S. The reason I need to integrate an array instead of a function is that I want to calculate Fourier coefficients for a curve I already have (which takes a lot of time for Matlab to generate). I don't want to have to re-generated the curve for each Fourier coefficient because that would be extremely computationally inefficient.
채택된 답변
추가 답변 (1개)
Khaled Khairy
2011년 3월 14일
0 개 추천
My suggestion is to use Gaussian quadrature! (see gaussquad function in the matlab file exchange) The only restriction is that your function will have to be evaluated at the Gaussian base points. The integration is then just a weighted sum (no need for quad or dblquad). I hope this helps.
댓글 수: 2
John D'Errico
2011년 3월 14일
You can't use Gaussian quadrature if the points are already given!
Khaled Khairy
2011년 3월 14일
True, however the way I understood the Post-Script of the original message, he can in fact generate the curve from scratch, it is just expensive to do so. Therefore I would generate it once using Gaussian quadrature basepoints and then do the weighted sum.
카테고리
도움말 센터 및 File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!