1function [x,h] = newtonSearchAlgorithm(b,n,tol)
2
3
4
5 notDone = 1;
6 aNew = 0;
7 a = 1;
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);
14 yint = curVal-slope*a;
15 aNew = -yint/slope;
16 h(cnt)=aNew;
17 if (abs(aNew-a) < tol)
18 notDone = 0;
19 elseif cnt>49
20 notDone = 0;
21 aNew = 0;
22 else
23 a = aNew;
24 end
25 end
26 x = aNew;
27