Example problem

Contents

(a)

Consider the function f(x) = sin(x)-x. Let x=10^-7 and print out y=f(x) with 15 digits.

How many of these digits are correct???

x = 1e-7;
y = sin(x) - x;
fprintf('y = %.15g\n',y)    % print y with 15 digits
y = -1.7205356741103e-22

(b)

Plot the function f(x) for x in [0,10^-7].

Why does the plot look like this???

x = linspace(0,1e-7,1000);  % vector of 1000 equidistant points 0,...,1e-7
y = sin(x) - x;             % vector of function values
plot(x,y)                   % plot vector y vs. vector x
xlabel('x')
title('function sin(x)-x')