I have a project on rounding errors and truncation error

Project 1 (Rounding vs. Truncation Errors)
1. Apply the backward difference schemes to approximate the derivative of the function, f(x)=e^x , at x = 1. 2. To investigate the effect of spacing of discrete points, h, a series of values of h are adopted, that is, h = 1/2n (n = 1, 2, …, 100). 3. Calculate and list the absolute error, eabs, for each choice of h (or n). Plot log10(eabs) vs. log10(h) and explain what you observe. Also derive the order of accuracy by calculating the slope in the truncation-error dominated part.
How can I solve this Project? I need to be calculate by hand and use MATLAB.

2 Comments

This is a very simple task. You will experience that by reducing the step-size, the rounding error will grow, while the truncation error will be smaller and smaller. Show what you have done so far.
I don't know what is the next step! It's my progress:
clc
format long
hn=[];
for n=1:100
h=1/(2^n);
hn=[hn;h];
end
disp(hn)

Sign in to comment.

Answers (1)

x=1.2; %value at which error has to be determined
f=@(x) exp(x); %defining the function
true_derivative=exp(x);%exact derivative result
for i=1:20
h(i,1)=0+.01*i;
n_d(i,1)=(f(x+h(i,1))-f(x))/h(i,1);%numerical derivative
e(i,1)=n_d(i,1)-true_derivative; %error
err(i,1)=abs(e(i,1)); %absolute error
end
plot(h,err);

Asked:

on 7 Jan 2015

Answered:

on 16 Nov 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!