You are on page 1of 5

Homework #3

Name:
ID:

1. The figure below illustrates the Newton-Raphson method used to find the
roots of differentiable functions.

y=f[xn ]+f'[xn ](x-xn )

set y=0 and solve for x

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

Printed by Wolfram Mathematica Student Edition


2 新建文件夹\\hw3.nb

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

3. The solution of 10 x Exp-x2  ⩵ 1 using 2.4 as initial guess

4. The solution of 10 x Exp-x2  ⩵ 1 using 2.6 as initial guess

5. The solution of (x - 2) (x + 2)4 == 0 using -3.0 as initial guess


6. The solution of (x - 2) (x + 2)4 == 0 using 1.4 as initial guess
7. The real root of 1 - x + x5 using 2.0 as initial guess
8. The real root of 1 - x + x5 == 0 using -2.1 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):

2. Consider the gas reaction:

H2(g) + CO2(g) ⇌ H2 O(g) + CO(g)

The equilibrium constant at 700 K is 0.106. A mixture of gases that initially

Printed by Wolfram Mathematica Student Edition


新建文件夹\\hw3.nb 3

contains 0.0150 M H2 and 0.0150 M CO2 is allowed to equilibrate at 700 K, use


the corresponding expression for the law of mass action and FindRoot to find
the final concentrations of all substances present. Express your final solution
using the correct number of significant figures.

3. The Cartesian coordinates of the four carbon atoms in a butane molecule


are given (in Å) in the following table:
In[ ]:= butane = {{"C1", 67.604, 23.354, 10.155}, {"C2", 66.47, 22.907, 9.232},
{"C3", 66.844, 21.608, 8.453}, {"C4", 65.695, 20.962, 7.727}};
butane //
Grid
C1 67.604 23.354 10.155
Out[ ]=
C2 66.47 22.907 9.232
C3 66.844 21.608 8.453
C4 65.695 20.962 7.727

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:

where i, j, and k, are the indices of the three atoms.

Printed by Wolfram Mathematica Student Edition


4 新建文件夹\\hw3.nb

The bond vectors are defined by the atoms' position vectors as

rij = ri - r j
rkj = rk - r j

The cosine of the angle θijk is given by

rij · rkj
cos θijk =
rij || rkj

A dihedral angle is defined by the positions of four atoms, as depicted in the


following diagram:

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

Printed by Wolfram Mathematica Student Edition


新建文件夹\\hw3.nb 5

The cosine and sine of the dihedral angle can be expressed as

u·v
cos ϕijkl =
u || v

(rij · v) rjk
sin ϕijkl =
u || v

Printed by Wolfram Mathematica Student Edition

You might also like