%compares three methods for computing the function 
%f(x) = (1-cos(x))/(x^2) at x = 10^(-n)

format long;    %tells Matlab to display 15 digits after the decimal point

f = @(x) x^(-2)*(1-cos(x));           %the limit of f at zero is 1/2
g = @(x) x^(-2)*sin(x)^2/(1+cos(x));  %g is the same as f
h = @(x) 1/2-x^2/24+x^4/720;   %first 3 terms of Taylor expansion of f

n = input('plug in x=10^(-n), where n = ');
x = 10^(-n);          %f fails at n>=8, g and h better than f when n>=5

disp('the values of f,g, and h at x are...') 
f(x)
g(x)   %trig identity version
h(x)   %taylor series version 



