%%%%%%%%%%%%%%%%%%%For Honors Calulus%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%By Evan Randles%%%%%%%%%%%%%%%%%%%%%%
%%%This function approximates the square root of a number
%%%a by the iterative method described on Homework 6,
%%%Exercise 1. You will input some number called a (>0)
%%%and an integer called n and it will compute the
%%%the values of the squence (x_n) up to N.

function SqrtApprox(a,N)
x=ones(1,N+1);  %Declaration of variable for (finite) sequence
y=zeros(1,N);    % An axiliary variable to text monotonicity
x(1)=a;  %Initialization (for Matlab, 1 is our 0)
for k=2:N+1 %A ``for loop" to iterate the computation
x(k)=(x(k-1)+a/x(k-1))/2;
if x(k)>x(k-1) %Test for increasing
    y(k)=1
end
end
y=sum(y)
if y==0
   fprintf("This sequence is increasing ")
else
    fprintf("This sequence is not increasing")
end
fprintf("and the %d th term is %f",N,x(N+1)) %Output
plot(x) %Graph of sequence up to N
clear all
end
