1 L. ‘1 J6,c’\9

advertisement
-
_r’fn
1
7L)
1
±
(1/)
L.
J6,c’\9
c\%jj4
‘1
2
V5
z1 h1b’S
7c I
Z7 9)\ \7E’
‘S
I
I
cJ
-
nvals
[10 30 50 100 1000]; % make array of possible n values:
=
j
= 1:length(nvals) %iterate over n values
n = nvals(j);
xvals = linspace(1,4, n+1); % returns an array of the interval 1 to 4
%divided into n+1 interval, i.e. our endpoints
for
4] so for left endpoints we want to
% xvals looks like [1 1.333
% toss the last point, right endpoints we want to toss the first
% in MATLAB, this is:
...
xvals_right = xvals(Z:end); % chops off first element
xvals_left = xvals(1:end-1); % chops off last element
deltax
f
=
(4-1)/n; % compute width of each rectangle
@(x) log(x); % define our function f using MATLAB syntax
=
f_right = f(xvals_right); % compute our right endpoint rectangle heights
f_left = f(xvals_left); % same for left
% notice we can put an array into a function, one of MATLAB’s strenghts
Rn
Ln
=
=
deltax*sum(f_right) % Rn = sum deltax
deltax*sum(f_left) % same for Ln
*
f(xj)
end
>>
riemann
n=
10
Rn=
2.7475
Ln=
2.3316
30
100
Rn=
2.5659
Ln=
2.5243
n=
1000
=2.5473
:n=
2.6139
n
\j’c,ILJ€
50
2. 5865
Ln
=
2.5034
n=
2.5431
(3
\
1
5
J
-
‘fli
RD
7L
()
1”
-7)(
)
Th
0
/\ç
—
-7
(
rJ
d
H
/
±
ç\
)
(
‘I
c7N
II
cJ
U
5—
‘I
-a-
2—
N
NJ
\cI
C”
CA
(N
()
37
c)
I’
—
)\
r\f
nf
)
LJ
—C
—9
I
C—
(I
2
-z
—
\.
N
1
—
—
WI
0
7
1
N
(
>(
N
>
C
0
cJ
c
‘C
p
j
—
I—
cZ
/
—
1—
(V
c)
(f
P
-icc
—
CN
ci
(
(
1)
C
Th
()
CN
-L
C
—s-
n
I
—
N
0
±
a
—
>-
c)
))
—
4
a
I
)
IN
0
XD
\\(
-7-
-7
Y3
Th
2
-/
2
I
rlv,
0
ec,
Download