0% found this document useful (0 votes)
22 views2 pages

MATH 3650 Homework 5

Uploaded by

corymoody5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

MATH 3650 Homework 5

Uploaded by

corymoody5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Homework 05

MATH 3650 Spring 2024 ©Timo Heister, [email protected]


1. The following data represents (time in s, distance traveled in meters) for a car:
(0, 0), (2, 40), (4, 80), (6, 130), (8, 180), (10, 250).
Use second order accurate formulas to approximate the speed at t = 0, t = 4 and t = 10.
Also convert the values into km per hour.
2. (a) Determine the error and convergence rate for the forward difference method for the
derivative of the function f (x) = sin(x) at x = 0 (see example from class).
(b) The order you will see is higher than what the theory tells us. What does the theory
say? Is there an error in the proof (why, why not?)? Note: If you are curious, you
would get the correct rates if you use x = 1 instead of x = 0.
(c) Create the Taylor expansion at x = 0 for sin(x) up to n = 6. Can this explain what is
happening in a)?
Discussion for a,b,c on paper and submit hw05q2.m that computes the rates for a).

3. Create a single script hw05q3.m that generates the output for:

(a) Use Forward Difference, Backward Difference, and Centered Difference to approximate
the first derivative of the function
f (x) = exp(x3 )
at the point x0 = 1 with values h = 41 , 18 , . . . , 2−10 .
(b) Then compute the absolute error (what is the exact value?) for each of the three
methods and show it as a table with columns h, errF D , errBD , errCD .
(c) Now create a log-log plot for each of those columns (x axis is h, y axis is the error). Is
the result what you expect?
(d) Compute the error rate for each of the columns (ratio between two consecutive entries)
and show it as a table with columns h, rateF D , rateBD , rateCD .
If err is a row vector containing your errors, you can use the expression
rate=[0, err(1:end-1)./err(2:end)];
4. Submit finite_difference_laplace.m and hw05q4.m :

(a) Create a function


function [x,u]=finite_difference_laplace(func,a,b,N,u_a,u_b)
that solves the boundary value problem
u00 (x) = f (x), a < x < b
u(a) = ua
u(b) = ub
on the interval [a, b] cut into N − 1 equal pieces and returns the points a = x1 < x2 <
· · · < xN = b in the vector x and the function values of the solution u at these points
in the vector u. The first parameter func is a function handle representing f (x).

1
(b) Use the code in a) to solve u00 (x) = cos(3x) with u(0) = 0 and u(5) = 1 for different
values of N : N = 7, N = 13, and N = 25. Plot the three solutions together with the
exact solution in a single plot. Include a legend. Hint: make sure that your boundary
values are correct and that your solution for N = 25 is very close to the exact solution.
The exact solution is:
1
u(x) = (8x + x cos(15) − 5 cos(3x) + 5)
45

You might also like