performing integration using quadgk

조회 수: 10 (최근 30일)
Ramakrishna
Ramakrishna 2013년 11월 19일
댓글: Walter Roberson 2013년 11월 19일
I would like to perform integration of y w.r.to x wherein I know the limits a, b (lower and upper limits for x) as well as the arrays x and y (n x 1 size each) using quadgk.
For example, see the below code:
x=0.0:0.1:5;
y=exp(x);
int_exact = exp(5) - exp(0);
int_trapz = trapz(x,y);
int_quadgk = quadgk(@integrand,0,5);
How can I code to get int_quadgk using the x and y arrays ONLY and NOT the function exp(x)? That is, I know only x and y arrays and NOT the function from which they were arrived at.
Please help.
Thanks

답변 (1개)

Walter Roberson
Walter Roberson 2013년 11월 19일
quadgk is strictly for the case where you can pass in a function. trapz() is suitable for numeric integration over a fixed set of data.
  댓글 수: 2
Ramakrishna
Ramakrishna 2013년 11월 19일
As you can see, there is considerable error between the exact value (int_exact) and that obtained using trapz (int_trapz). Hence, I plan to use quadgk to minimise the error.
Alternatively, is there a different way to numerically evaluate the integral with reduced / no error?
Thanks

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by