limit to infinity of Left Riemann Sum

조회 수: 4 (최근 30일)
Stelina
Stelina 2014년 11월 2일
댓글: Torsten 2014년 11월 3일
Hi there,
Lets say I have created a function Sn=LeftRiemannSum(f,left,right,N) ,that computes the left riemann sum over the interval left to right with N subdomains.i.e.:
Sn=sum(f(xi)*h) for all subdomains i=0 to N-1. f is my function and xi=left+i*h , so the input arguments left=x0 and right=xN.
Let f be my anonymous function (ex f=@(x)(x.*log(1+x)) .
I also estimated the Sn for varying N, from N=10 to 100000.
Now, I simply want to compute the value of the series Sn when N -> infinity. Inside the function I have a for loop [ for i=0:(N-1)] so I will have endless loop ..
Can I pass the function somehow to the 'limit' command? Any clues?
Thanx!
PS: The main part of the code of my function LeftRiemann Sum is the following:
if true
for i=0:(N-1)
x=x0+i.*h;
y=f(x);
A=y.*h;
S=S+A
end
Sn=S
end

채택된 답변

Zoltán Csáti
Zoltán Csáti 2014년 11월 3일
If I am not mistaken, you try to determine the limit of the left Riemann-sum for the value of the definite integral. Of course you can't take infinite members. If you want to use this approach, I recommend you to use a large number for N and also estimate the right Riemann-sum. If the two sums are approximately equal, then there is hope that this is the approximate value of the integral.
A comment: it can easily be vectorized:
N = 1000;
a = 1;
b = 2;
h = (b-a)/N;
x = x0+(0:N)*h;
fx = f(x);
sum(fx*h);

추가 답변 (1개)

Torsten
Torsten 2014년 11월 3일
Use
S_inf = integral(f,left,right)
to get the limit.
Best wishes
Torsten.
  댓글 수: 3
Stelina
Stelina 2014년 11월 3일
Yes, I should have clarified. I already integrated my function analytically with
syms x;f=x.*log(1+x);
F=int(f) %integrate
a=0;b=1;
area=int(f,a,b)
, so I know the exact result.
Though, I still don't quite get whats the point of this homework exercise. For example, even if I use a relatively not that large value for N (I tried N=10000000) to substitute "inf", I get the exact same number, meaning my numerical approximation is perfect.
Besides, I guess MATLAB uses sth like that to calculate int "analytically" right?
Lol, I should ask MATLAB.
Torsten
Torsten 2014년 11월 3일
If you use "int", MATLAB tries to analytically determine a function F such that F'=f.
In your case, F(x)=0.25*(2*(x^2-1)*log(1+x)-(x-2)*x).
Thus in the limit you get F(1)-F(0)=0.25.
Best wishes
Torsten.

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

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by