As mentioned in class the forward difference formula for numerical differentiati
ID: 3109366 • Letter: A
Question
As mentioned in class the forward difference formula for numerical differentiation f'(x_0 + h) - f(x_0)/h deteriorates as the step-size h decreases. (a) Why does it deteriorate? (b) Write a computer program to implement the following pseudocode to approximate f' (x_0) at the point x_0 = 0.6 where f (x) = cos x. It uses the forward difference formula and a decreasing choice of h values. n leftarrow 10 x_0 leftarrow 0.6 for i = 1 to n h leftarrow 0.025 y leftarrow cos (x_0 + h) - cos (x_0)/h error leftarrow |sin(x_0) + y/sin(x_0)| output i, h, y, error end Comment on your observations.Explanation / Answer
A) forward difference formula deteriorate as h is decreased still further. The reason that the approximations lose accuracy for very small h is due to loss of significance. The formula subtract nearly equal numbers and lose significant digits, and then to make matters worse, magnify the effect by dividing by a small number.
B)
clc;
clear all;
x=0.6;
n=10;
for i=1:n
h(i)=0.025^i;
y(i)=(cos(x+h(i))-cos(x))/h(i);
error(i)=abs((sin(x)+y(i))/sin(x));
end
disp('i h y error')
disp('______________________________________________________________')
for i=1:n
fprintf('%d %.16f %f %f ',i,h(i),y(i),error(i))
end
i h y error
______________________________________________________________
1 0.0250000000000000 -0.574900 0.018166
2 0.0006250000000000 -0.564900 0.000457
3 0.0000156250000000 -0.564649 0.000011
4 0.0000003906250000 -0.564643 0.000000
5 0.0000000097656250 -0.564642 0.000000
6 0.0000000002441406 -0.564643 0.000000
7 0.0000000000061035 -0.564651 0.000015
8 0.0000000000001526 -0.564614 0.000050
9 0.0000000000000038 -0.552973 0.020667
10 0.0000000000000001 -1.164153 1.061753
at i=9 begin to the deteriorate
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.