$24
The following tasks comprise the second homework assignment for the class. In the class, we have talked about a few basic content items.
Task 1. Approximation of the Second Derivative of a Function.
Using Taylor series prove that the approximation
f ′′(x ) ≈ f (x0 − h) − 2f (x0) + f (x0 − h)
0 h2
is of order h2. Write the expression in the form of
∣
f (x + h) − 2f (x ) + f (x − h) ∣
∣
′′
(x0) −
0
0
0
∣
≤ C h
2
∣f
∣
2
∣
h
∣
This is similar to the work we did on the first derivative approximation. You can write out the details using pencil and paper to do the derivation. If your work is handwritten, scan the work into a pdf file and include the pdf in your submission.
Task 2. Computer Code For Second Derivative Approximation.
Create a code to perform the approximation of the derivative given in the previous task. The code should accept as input
the function, f (x),
the point, x0, where the approximation is to be computed, and the initial increment, h parameter.
Output the result of the approximation. Test your code on the function
(x − π ) tan2(x)
f (x) = 2
x2 + 65
for x0 = π4 . Print out a few values of the derivative approximation of the given function.
Task 3. Computational Convergence Study
Write a routine that will fit data sets to a linear polynomial as described in class. The code should accept as input
a data array, x, containing the input values, and a data array, y, of the measured output.
The output should include two real numbers, a and b, the approximate coefficients for the linear fit. Test your code on the data provided by the code in Task 2 of this assignment. Use a point like x0 = 1.0 for the function defined in the task.
Task 4. Starting a Shared Library for Computing Errors.
Create 2 routines, one for computing the absolute error and one for computing the relative error between a number, say u, and some approximation, v, of the original exact value. Also include routines that output the number of digits of accuracy for both single and double precision. Create a shared library for collecting routine for computing errors that is separate from the root finding archive created earlier in the course.
Task 5. Implementing the Explicit Euler Method.
In class we considered the approximate solution of initial value problems of the form
dxdt = f (t, x(t))
with initial condition xt)0) = x0 via the Explicit Euler method. Implement this method for application to the Logistic equation
dPdt = α P − β P 2
with P (0) = P0 . Your code should accept as input
the growth constant, α > 0,
the limiting constant, β > 0, and
the initial value, P0 , to start the simulation.
Test your codes for some given values of the parameters:
test 1: α = 0.2, \beta=0.0005, and P0 = 10.0
test 2: α = 0.01, \beta=0.0005, and P0 = 10.0
test 3: α = 2.0, \beta=0.0005, and P0 = 10.0