Newton raphson method is used for optimization of functions and is based on taylor series expansion. Here is the code for a three level newton raphson method.
 

restart; with(Student[MultivariateCalculus]); ff := proc (xx) xx^3-2*xx+2 end proc; ii := 0; XX[ii] := 2; while ii < 25 do GR := Gradient(ff(xx), [xx] = [XX[ii]]); GR1 := evalf(GR[1]); HESS := Student[VectorCalculus]:-Hessian(ff(xx), [xx] = [XX[ii]]); HESS1 := evalf(HESS[1]); YY[ii] := XX[ii]-GR1[1]/HESS1[1]; GR := Gradient(ff(xx), [xx] = [YY[ii]]); GR1 := evalf(GR[1]); HESS := Student[VectorCalculus]:-Hessian(ff(xx), [xx] = [YY[ii]]); HESS1 := evalf(HESS[1]); ZZ[ii] := YY[ii]-GR1[1]/HESS1[1]; GR := Gradient(ff(xx), [xx] = [ZZ[ii]]); GR1 := evalf(GR[1]); HESS := Student[VectorCalculus]:-Hessian(ff(xx), [xx] = [ZZ[ii]]); HESS1 := evalf(HESS[1]); ii := ii+1; XX[ii] := ZZ[ii-1]-GR1[1]/HESS1[1]; printf("%a\n", XX[ii]) end do

.8180854533
.8164965808
.8164965808
.8164965808
.8164965808
.8164965808
.8164965808
.8164965808
.8164965808
.8164965808
.8164965808
.8164965808
.8164965808
.8164965808
.8164965808
.8164965808
.8164965808
.8164965808
.8164965808
.8164965808
.8164965808
.8164965808
.8164965808
.8164965808
.8164965808

 

ff(.8164965808)

.911337892

(1)

with(Optimization); Minimize(xx^3-2*xx+2, xx = -2 .. 2)

[HFloat(0.9113378920963653), [xx = HFloat(0.8164965785244629)]]

(2)

NULL


 

Download THREE_LEVEL_NEWTON_RAPHSON_METHOD1.mw


Please Wait...