THE FIRST FEW CELLS (THAT LOOK EMPTY) CONTAIN THE CODE FOR THE COMMANDS USED BELOW. I WOULDN'T RECOMMEND DELETING THEM.
The command newtons uses Newton's method to attempt to find one zero of a function . Given an equation of the form , the syntax for newtons is
newtons[f(variable), variable, starting value, number of iterates].
For example, to find one solution to the equation, we would plot the function to find a good estimate for the location of the zero. (I won't put the graph here to keep the file small.)
f
f(x)=0
newtons[f(variable), variable, starting value, number of iterates].
For example, to find one solution to the equation
cosx-x=0
In[]:=
Plot[Cos[x]-1/4x+1,{x,0,8}]
Out[]=
In[]:=
newtons[Cos[x]-1/4x+1,x,0,10]
Out[]//MatrixForm=
0. |
8. |
7.07573 |
7.0062 |
7.0043 |
7.00429 |
7.00429 |
7.00429 |
7.00429 |
7.00429 |
7.00429 |
In[]:=
newtons[Cos[x]-x,x,1,15]
Out[]//MatrixForm=
1. |
0.750364 |
0.739113 |
0.739085 |
0.739085 |
0.739085 |
0.739085 |
0.739085 |
0.739085 |
0.739085 |
0.739085 |
0.739085 |
0.739085 |
0.739085 |
0.739085 |
0.739085 |
In[]:=
newtons[x^2-2,x,1,5]
Out[]//MatrixForm=
1. |
1.5 |
1.41667 |
1.41422 |
1.41421 |
1.41421 |
In[]:=
newtonsexact[x^2-2,x,1,5]
Out[]//MatrixForm=
1 |
3 2 |
17 12 |
577 408 |
665857 470832 |
886731088897 627013566048 |
One more example. Let us find all of the zeroes of the function . First, graph it.
f(w)=-4+3w-3
5
w
4
w
In[]:=
Plot[-4+3w-3,{w,-2,5}]
5
w
4
w
There appears to be only one zero near .
w=4
In[]:=
newtons[-4+3w-3,w,4,10]
5
w
4
w
The zero is approximately .
3.96399