a)Write a short code to implement the compound trapezoid rule on the interval [a, b].
b)Use the trapezoid code to compute approximations to ㏒ 2 = ∫dx/x (上界2, 下界1) for n = 5, 10, 20, 40.
c)Compare your approximate values to "exact" values for ㏒ 2 found on your calculator or computer. Compute the error for n = 5, 10, 20, 40. Does it behave as predicted by theorem 7.18?
Theorem 7.18
Let f€C^2[a, b].Then there is a point η€[a, b], such that the compound trapezoid rule and its error are given by
∫b a f(x)dx = h/2[ f(x_0) + 2f(x_1) + ... + 2f(x_n-1) + f(x_n) ] + ΕT(f),
ΕT(f) = -(b - a)/12 * h^2 * f"(η).
IF f is convex, f" > 0, the midpoint rule produces a number Μ(f) < ∫b a f, and the trapezoid rule produces a numder Τ(f) > ∫b a f.
請告訴我詳細的解答
感激不盡
2007-12-27 17:28:38 · 1 個解答 · 發問者 筱小小 1 in 科學 ➔ 數學
a) 簡碼如下:
input n '分段數
h=1/n '分段寬度
res=0 '記錄積分值
for i=0 to n
x=1+i/n
res=res+2/x '求總和
next i
res=h*(res-1-1/2)/2 '求積分值
err=log(2)-res '求誤差
η=-1/(6*n^2*err)^(1/3) '求Thm 7.18之η
print "梯形法n="; n ; "結果="; res; "誤差="; err; "η="; η;
if (η>1)and(η<2) then
print "符合Thm 7.18"
else
print "不符合Thm 7.18"
endif
b, c)執行結果如下:
梯形法n=05,結果=0.69563492063,誤差=-0.002487740
η=1.388996803 符合Thm 7.18
梯形法n=10,結果=0.69377140318,誤差=-0.000624223
η=1.387297968 符合Thm 7.18
梯形法n=20,結果=0.69330338179,誤差=-0.000156201
η=1.386866849 符合Thm 7.18
梯形法n=40,結果=0.69318624001,誤差=-0.000039059
η=1.386758652 符合Thm 7.18
2007-12-28 19:40:37 · answer #1 · answered by mathmanliu 7 · 0⤊ 0⤋