Root Finding and Optimization: DG (X) DX DG (X) DX
Root Finding and Optimization: DG (X) DX DG (X) DX
Bisection
1 μGMm a(1 e 2 )
=
r L
2 [1 ecos( + 0 )] r =
1 ecos( + 0 )
where r = r1 r2
m1m2
and Reduced mass : μ =
m1 + m2
rmin + rmax L2 1
a= =
2 μGMm 1 e 2
L2 1
b=
μGMm 1 e 2
f()
Need a starting interval for the bisection algorithm: We note that
the maximum and minimum of the sin() term is 1, -1. So we can
take as the starting range for 2t 2t
a = e b = +e
T T
Winter Semester 2006/7 Computational Physics I Lecture 11 5
2-body motion
Let’s take some random values for the parameters:
T=1, a=1, e=0.6, m2=4m1
accuracy=1.D-6 2t
* Define range in which we search (
tfunc= esin )
angle1=2*3.1415926*t-e T
angle2=angle1+2.*e
try1=tfunc(e,period,t,angle1) angle1=angle2
try2=tfunc(e,period,t,angle2) try1=try2
If (try1*try2.gt.0) then angle2=angle2+step/2.
print *,' Cannot find root - bad start parameters' try2=tfunc(e,period,t,angle2)
return If (try1*try2.lt.0.) goto 2
Endif If (try1.eq.0.) then
* Now update until within accuracy angle=angle1
1 continue return
step=angle2-angle1 Elseif (try2.eq.0.) then
angle2=angle1+step/2. angle=angle2
try2=tfunc(e,period,t,angle2) return
If (try1*try2.lt.0.) goto 2 (root in this interval) Endif
If (try1.eq.0.) then 2 continue
angle=angle1 If ((angle2-angle1).gt.accuracy) goto 1
}
return angle=angle1+(angle2-angle1)/2.
Elseif (try2.eq.0.) then (check for exact landing)
angle=angle2
return Note: accuracy2-(# iterations).
Endif
For 10-6, need 21 iterations
Winter Semester 2006/7 Computational Physics I Lecture 11 6
2-body motion
Here we use the slope (or also 2nd derivative) at a guess position
to extrapolate to the zero crossing. This method is the most
powerful of the ones we consider today, since we can easily
generalize to many parameters and many equations. However, it
also has its drawbacks as we will see.
2t
( esin ) = tfunc(e, period,t,angle)
T
(1 ecos ) = tfuncp(e, period,t,angle)
Modified
Regula Falsi Newton-Raphson
f 1 f 1
We form the derivative matrix:
x 1 x n
Df =
f n f n
x x
1 n
The iteration is x
(r +1) (r )
( )
(r ) 1 (r )
= x Df ( x ) f ( x )
Winter Semester 2006/7 Computational Physics I Lecture 11 15
Optimization
We now move to the closely related problem of optimization
(finding the zeroes of a derivative). This is a very widespread
problem in physics (e.g., finding the minimum 2, the maximum
likelihood, the lowest energy state, …). Instead of looking for
zeroes of a function, we look for extrema.
t h h
g ( x ) = ,, a vector
x 1 x n
2h 2h
x x x x
1 1 1 n
H( x ) = the Hessian matrix
2
h h
2
x nx1 x nx n
General technique:
1. Start with initial guess x ( 0)
2. Determine a direction, s, and a step size
3. Iterate x until g t < , or cannot find smaller h x ( r +1) = x (r ) + r sr
Winter Semester 2006/7 Computational Physics I Lecture 11 17
Steepest Descent
Reasonable try: steepest descent
h( x g r)
sr = gr step length from 0 = r
Note that consecutive steps are in orthogonal directions.
As an example, we will come back to the data smoothing
example from Lecture 3:
2 are the parameters of the function to be fit
n
(yi f (xi ; ))
=
2
2
yi are the measured points at values xi
i=0 wi
wi is the weight given to point i
1. Write a code for the 2-body motion studied in the lecture, but
using numerically calculated derivatives (secant method).
Compare the speed of convergence to that found for the NR
method.