numerical integration

조회 수: 18 (최근 30일)
u
u 2012년 5월 11일
Recently, when I use Gauss-Legendre Formula to handle it. But it is not correct. So I want someone to help me to solve this problem, thanks for your attention!
This equation is: 1/(1-18/9*x+8/9*exp(3*(x-1))), and the integrating range is [1,H], and 0<=H<=1.
Generally speaking, for any H, this result is positive, but for my code, there are some negetive number, and this puzzle me for a very long time, and did not fint the answer.
so, now i give my code. And i do not know how to handle it.
function s=traprl(f,a,b)
% [a,b] is the integrate region, b always equals unity, and f is the function
h=(b-a)/10000;
s=0;
for k=1:10000-1
x=a+h*k;
s=s+feval(f,x);
end
s=h*(feval(f,a)+feval(f,b))/2+h*s;
function y=fh(x)
y=1/(-2/9+(10/9)*x-8/9*exp(4*(x-1)));
Thanks!
  댓글 수: 2
Sargondjani
Sargondjani 2012년 5월 11일
can you be (alot) more specific?
what did you try? (your code)
what (do you think) should be the answer?
Walter Roberson
Walter Roberson 2012년 5월 14일
If 0 <= H <= 1 and the integrating range is [1,H], then is there a reason you did not describe the integrating range as being [H,1] ?

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

답변 (2개)

Mike Hosea
Mike Hosea 2012년 5월 12일
You can't just integrate over the singularity near x=0.66. That's why you're getting the wrong answer.
  댓글 수: 2
u
u 2012년 5월 14일
If I want to integral from zero to one, should I except singularity x=0.66,thank you!
Mike Hosea
Mike Hosea 2012년 5월 14일
I don't know what you mean by "except". You can integrate from 1 down to some number larger than r, where x=r is the location of the singularity. Since the numerator is 1, r is a root of the denominator, easily found to good accuracy with FZERO. The singularity is a barrier. It is too strong for QUADGK to handle (I tried what Titus suggested before I responded the first time). The linear term in the denominator troubles me--I don't think it's an integrable singularity.

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


Titus Edelhofer
Titus Edelhofer 2012년 5월 14일
Hi,
I would suggest to compute the position of the singularity (e.g. using fzero) and try quadgk on the left integral and the right integral separately.
Titus

카테고리

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