1function [x,h] = newtonSearchAlgorithm(b,n,tol)
 2% Given, "a", this function finds the nth root of a
 3% number by finding where: x^n-a=0.
 4
 5    notDone = 1;
 6    aNew    = 0;    %Refined Guess Initialization
 7    a       = 1;        %Initial Guess
 8    cnt     = 0;
 9    h = zeros(1,50);
10    h(1)=a;
11    while notDone
12        cnt = cnt+1;
13        [curVal,slope] = f_and_df(a,b,n); %square
14        yint = curVal-slope*a;
15        aNew = -yint/slope;     %The new guess
16        h(cnt)=aNew;
17        if (abs(aNew-a) < tol)  %Break if it's converged
18            notDone = 0;
19        elseif cnt>49 %after 50 iterations, stop
20            notDone = 0;
21            aNew = 0;
22        else
23            a = aNew;
24        end
25    end
26    x = aNew;
27