Newton's Method

You can download the Newton's Method here. Put this file to your matlab  directory. To execute the Newton's method, open your matlab program:

  Using Toolbox Path Cache. Type "help toolbox_path_cache" for more info.

To get started, select "MATLAB Help" from the Help menu.

>>

For instance, if you want to do example 2 on page 281, you can do:

>> f='sin(3*x)-cos(x)'

f =

sin(3*x)-cos(x)

>> Newton(f, 0.4, 4)


1.0000   0.3926   -0.0002

2.0000   0.3927   -0.0000

3.0000   0.3927   -0.0000

4.0000   0.3927   0.0000
If you are not satisfied with four decimal places, you do


>> format long
>> Newton(f, 0.4, 4)


1.00000000000000  0.39256474474919   -0.00020570078629

2.00000000000000  0.39269903816472   -0.00000006663898

3.00000000000000  0.39269908169872   -0.00000000000001

4.00000000000000  0.39269908169872    0.00000000000000

This solves the equation f=0  by four iterations with initial guess 0.4.

If you want to start with another initial guess, for ex: 0.2, you do

 >> Newton(f, 0.2, 6)


1.00000000000000   0.35531753273452  -0.06228600122207

2.00000000000000   0.38994202442391  -0.00424837394140

3.00000000000000   0.39268101959338  -0.00002764947949

4.00000000000000   0.39269908091119  -0.00000000120550

5.00000000000000   0.39269908169872  0.00000000000000

6.00000000000000   0.39269908169872  0
If you want to continue example 3 on page 281, you do

>> clear
>> f='x^4-6*x^2+x+5'

f =

x^4-6*x^2+x+5

>> Newton(f,0,7)
1 -5 475

1.0e+002 *

0.02000000000000 -0.03917995444191   1.44621506056958

3.00000000000000 -3.16694805728908   42.24776570210613

4.00000000000000 -2.68712701380716   11.12677281628375

5.00000000000000 -2.43633031925806   2.18203602039247

6.00000000000000 -2.35729793861145   0.18020224687632

7.00000000000000 -2.34950003482378   0.00165807253059

>> Newton(f,-1,4)
1.00000000000000 -0.88888888888889  -0.00533455265966

2.00000000000000 -0.88828661401063  -0.00000045755408

3.00000000000000 -0.88828656234358  -0.00000000000000

4.00000000000000 -0.88828656234357   0

Play with it and have fun !