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
f
. Given an equation of the form
f(x)=0
, the syntax for newtons is
​
​newtons[f(variable), variable, starting value, number of iterates].
​
​For example, to find one solution to the equation
cosx-x=0
, 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.)
In[]:=
Plot[Cos[x]-1/4x+1,{x,0,8}]
Out[]=
2
4
6
8
-1.0
-0.5
0.5
1.0
1.5
2.0
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
f(w)=
5
w
-4
4
w
+3w-3
. First, graph it.
In[]:=
Plot[
5
w
-4
4
w
+3w-3,{w,-2,5}]
There appears to be only one zero near
w=4
.
In[]:=
newtons[
5
w
-4
4
w
+3w-3,w,4,10]
The zero is approximately
3.96399
.