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

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)

댓글을 달려면 로그인하십시오.

답변 (1개)

Arkayan Laha
Arkayan Laha 2018년 11월 16일

0 개 추천

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);

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2015년 1월 7일

답변:

2018년 11월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by