%this file iterates with the newton's method applied to
%x^2-a=0, in order to find sqrt(a).
% the quadratic convergence of the newton's method is apparent from
%the iterations.
clear x, clear y
disp('this .m file will find successive approximations to the number sqrt(a)')
disp('using Newton''s method.') 
a=input('type in your choice of the number a: ');
x(1)=input('please type in your crude approximation to sqrt(a): ');
y=sqrt(a)*ones(1,4);
for n=2:4;
  x(n)=(x(n-1)^2+a)/(2*x(n-1));
end
format long
error=x-y
disp(sprintf('the square root of %4.2f is', a))
x(4)
