% wachkyPlot0.m 
% Effects of cancellation and rounding in computing 
% f(x) = (1-cos(x))/x^2
% when x is getting close to sqrt(eps) or less.
% K. Ming Leung, 01/22/04

% One can produce a graph by entering a one line command
% using MATLAB's easy plotting function called ezplot:
% ezplot('(1-cos(x))./(x.*x)',[0,10]);
% ezplot('(1-cos(x))./(x.*x)',[0,1e-2]);

% One can also produce a graph by first computing the function
% and then plot the result using MATLAB's "plot" function:
clear all; 
x = linspace(eps,1e-7,50000); % create abscissa points

% compute function values in a straightforward (vectorized) way:
y0 = (1-cos(x))./(x.*x);    

% plot the function using a solid line
p = plot(x,y0,'-');

% plot the function using a thicker solid line
%p = plot(x,y0,'-','LineWidth',1.5);

% Put a title, and labels for the x and y axes with optional
% control of various font sizes:
title('f(x) = (1 - cos(x))/x^2','fontSize',16);
xlabel('x','fontSize',24);
ylabel('f(x)','fontSize',24);
set(gca,'FontSize',14);
