Homework #3 Name: ID:: y F (X) +F' (X) (X-X)
Homework #3 Name: ID:: y F (X) +F' (X) (X-X)
Homework #3 Name: ID:: y F (X) +F' (X) (X-X)
Name:
ID:
1. The figure below illustrates the Newton-Raphson method used to find the
roots of differentiable functions.
f[x]
exact root x=xi+1 =xi - f[xi ]
f'[xi ]
xi
xi+1
Start with a trial value, x0, close to the root. The next estimate can be found
with the iterator indicated in the figure above. Repeat the process until the
iteration converges to a given accuracy, δ, (i.e. xi+1 - xi < δ), or a maximum
number of iterations is reached.
Implement a function newtonMethod[f_, x0_, acc_, maxiter_] that
computes a numerical estimate of a root of a given function f[x]. The first
argument is the name of the function, the second is the initial guess value, the
third is the accuracy as defined above, and the fourth is the maximum
number of iterations. You must use the function While to implement the
iterator (see the Mathematica documentation for details on While). Use Break
to exit the While loop once the root estimate converges. The function f[x]
should be implemented separately, outside the scope of newtonMethod. The
last two arguments should be optional with default values of 10-9and 100,
respectively (see the Mathematica documentarian for details on how to
specify optional arguments). The output should be a list of two elements the
final root estimate and the total number of iterations.
a) Test your implementation with the following cases using the default values
of accuracy and maximum number iterations. Evaluate f[x] at the resulting
root value.
1. The value of 2 using 1.41 as initial guess (propose the appropriate function)
2. The solution of 10 x Exp-x2 ⩵ 1 using 2.0 as initial guess
b) Collect your results in a 4-column table with the case number (1 through 10)
in the first column, the resulting root from your function, the evaluation of
f[x] at the resulting root value, and the number steps. The table should be
ordered by case number. Use TableForm and label each column.
c) Rank the convergent cases in terms of convergence rate (total number of
iterations) from the fastest to the slowest. Provide you answer indicating the
case numbers in the text cell shown below (in blue).
Convergent cases (fastest to slowest):
a) Use Norm to calculate the C1-C2, C2-C3, and C3-C4 bond lengths (in Å)
b) Use Dot and ArcCos to calculate the C1-C2-C3 and C2-C3-C4 angles (in
degrees in the range [0,180])
c) Use Cross, Dot, and the 2-argument version of ArcTan to calculate the C1-
C2-C3-C4 dihedral angle (in degrees in the range [0,360])
All the necessary formulas are given in the appendix found below.
Appendix
The angle between two bonds sharing a common atom is defined by the
positions of the three atoms, as depicted in the following diagram:
rij = ri - r j
rkj = rk - r j
rij · rkj
cos θijk =
rij || rkj
Import["http://cbio.bmt.tue.nl/pumma/uploads/Theory/dihedral.png"]
where i, j, k, and l are the indices of the four atoms, and the dihedral angle,
ϕijkl, is defined as the angle between the planes that contain atoms i, j, k and
atoms j, k, l. The normal to those planes are given by
u = rij ⨯ rjk
v = rlk ⨯ rjk
where the bond vectors are defined by the atoms position vectors as
rij = ri - r j
rjk = r j - rk
rlk = rl - rk
u·v
cos ϕijkl =
u || v
(rij · v) rjk
sin ϕijkl =
u || v