Matematik och Datavetenskap, Chalmers Tekniska Högskola och Göteborgs Universitet
The goal of this exercise is to study how fast the error of your approximate integral decreases when the stepsize h decreases. See EM2000 chapter 30.
1. The algorithm in The Fundamental Theorem is called the RECTANGLE
RULE.
Create a row vector h of stepsizes: h(1)=1e-1, ...,
h(5)=1e-5.
Then run
[x,u]=my_int('cos', [0, 1], 0, h(1))
and so on. For each step compute the absolute value of the error and save it in a vector e:
e(1)=max( abs(u-sin(x)) )
and so on.
Make a table by putting h and e as columns in a matrix: A=[h' e']. Then change to long format format long and type A.
How many decimals of accuracy do you gain each time the step is decreased by a factor 10?
Save the table for the documentation.
Plot the error versus the stepsize: plot(h,e,'x-'). Is this plot useful? Instead plot the logarithms of h and e: plot(log(h),log(e),'x-'). The argument 'x-' puts a cross at each point and draws a straight line between the points.
Note: The natural logarithm ln(x) is called log(x) in English and in matlab.
Save or print the figure for the documentation.
2. THE MIDPOINT RULE. Now change the program my_int so that it uses the midpoint values of f, f(xi+h/2), instead of the left end values f(xi). (This algorithm is called the midpoint rule.) Then repeat all the computations in 1.
How many decimals of accuracy do you gain each time the step is decreased by a factor 10?
3. The theory says that e < Khs for some positive number s. According to formula (27.32) in EM2000 we have s=1 for the rectangle rule. If we take the logarithm of this inequality we get
log (e) < log (K) + s log (h)
so the slope in your diagram is s. Read off s from your diagrams. What do you get for the rectangle rule and for the midpoint rule?
4. Write a short report about this experiment for your individual folder. Include the tables and the figures.
/stig