Vous êtes sur la page 1sur 2

PHYS3071/7073 - Assignment 4 - Due Tuesday 27th March 2012 by 9.

30am

Error Orders

Theory
In worksheet 7 we presented several dierent methods for estimating derivatives. In this assignment we shall derive quantitative estimates for the orders of two of the approaches: the 2-point forward dierence and the 2-point central dierence approximations. The key mathematical insight is as follows. Suppose that we have a model which is a power law, y = bxa , where we are interested in determining a. By taking the logarithm of both sides, we obtain ln y = ln (bx ) = a ln x + b. This is very signicant we have transformed our power law model into a linear model, for which we already know how to compute the best t using the linear least squares approach! In conclusion we see that if we are given a set of (x, y) data points from some power law model y = bxa , then by applying the linear least squares method to (ln x, ln y), we can extract the power a from the slope.

Problem 1/3: Generating data

In order to do our analysis of the order of the two methods of approximating derivatives, we need to generate some data that gives us a picture about how fast the error here dened as the absolute dierence between our approximation to a derivative and its exact value shrinks as we shrink the increment dx; and while we are generating this data, we may as well take the logarithm of it immediately to save us from having to do so later. This is the basis behind this problem, for which you must do the following: Write a program that takes as input values of dx in as04 errororders.dat, and produces as output two les, as04-forward.dat and as04-central.dat, which contain for each value of dx the value of log(dx) and the value of the logarithm of the absolute dierence between the exact derivative of ex at x = 1 and the approximation using respectively the forward and central dierence methods. The input le as04 errororders.dat consists of lines with the format (ES8.1) and contains the following data: +1.0E-02 +2.5E-02 +5.0E-02 +1.0E-01 (This le can be downloaded from http://gcross.github.com/PHYS3071/as04 errororders.dat.) Every line in the two output les must have the format (ES8.1,1X,ES8.1), or else you will have problems reading the data back in when performing the linear least squares analysis. After you have written this program, run it to generate the two output les. 1

Problem 2/3: Analyzing data

Using the program you wrote in class for Worksheet 8, run a linear least squares t on the data in as04-forward.dat and as04-central.dat. When the error of a dierence method scales like dx (where is an integer) we say that it is an th order method. Based on your analysis, what are the orders of the forward and central dierence methods? Which method is better, and why? Create a le coursenumber-as04-problem2-surname-studentid.txt into which you copy and paste: the contents of as04-forward.dat and as04-central.dat, labeling each le; the result of running your linear least squared analyses on the two data sets; and your answer to the above questions.

Problem 3/3: Plotting data

For each of as04-forward.dat and as04-central.dat, plot both the raw data and your best t; the raw data should be plotted using points and the best t should be plotted using lines. Make sure that the plot looks nice e.g., that your axes are labeled appropriately, that the whole plot as well as the individual plot items have appropriate titles, etc. as you will be graded on this. Save the results to respectively coursenumber-as04-problem3-forward-surname-studentid.ps and coursenumber-as04-problem3-central-surname-studentid.ps.

Submission
To submit your assignment: 1. Copy the program your wrote in Problem 1 to coursenumber-as04-problem1-surname-studentid.f90 2. Copy the program you wrote in Worksheet 8 that you used in this assignment to perform the linear analysis to coursenumber-as04-leastsquaresfit-surname-studentid.f90 3. Use a2ps or enscript and then print to create hard-copies of the source code and data output les, namely: coursenumber-as04-problem1-surname-studentid.f90 coursenumber-as04-problem2-surname-studentid.txt coursenumber-as04-problem3-forward-surname-studentid.ps coursenumber-as04-problem3-central-surname-studentid.ps coursenumber-as04-leastsquaresfit-surname-studentid.f90 4. zip or tar the above les into a single archive and e-mail it as an attachment to the tutor with subject: Coursenumber Surname Studentid Assignment 04. 2

Vous aimerez peut-être aussi