Implement the Newton's method with simple backtracking linesearch algorithm where the derivatives in the Jacobian matrix are calculated numerically using finite differences.
The interface to the function could be something like
static vector newton(Func<vector,vector>f, vector x0, double eps=1e-2);The routine returns a vector, x, that approximates the root of the equation f(x)=0. The parameters are:
The value δxi to be used in the finite-difference numerical evaluation of the Jacobian can be chosen as
δxi = |xi|*2-26where 2-26 is the square root of the machine epsilon.
One should stop one's iterations if either the condition ‖f(x)‖<ε is satisfied or if the step-size becomes smaller than the δx parameter.
You should use your own routines for solving linear systems.
Debug your root-finding routine using some simple one- and two-dimensional equations.
Find the extremum(s) of the Rosenbrock's valley function,
f(x,y) = (1-x)2+100(y-x2)2by searching for the roots of its gradient (you should calculate the latter analytically).
(3 points) Bound states of hydrogen atom with shooting method for boundary value problems
The s-wave radial Schrödinger equation for the Hydrogen atom reads (in units "Bohr radius" and "Hartree"),
-(1/2)f'' -(1/r)f = εf ,
The bound s-state wave-function satisfies this equation and the two boundary conditions,
f(r → 0) = r-r², (prove this)
f(r → ∞) = 0 .
These two boundary conditions can only be satisfied for certain discrete (negative) values of the energy.
Since the Coulomb potential diverges at zero one cannot specify the boundary condition at r=0 numerically. Instead one can use some finite radius rmin, that is much smaller than the Bohr radius, and specify the boundary condition at rmin,
f(0)=0 → f(rmin)=rmin-rmin2 .
Since one cannot integrate numerically to ∞ one substitutes ∞ with a reasonably large number, rmax, such that it is much larger than the typical size of the hydrogen atom but still managable for the numerical inregrator (say, rmax = 10 Bohr radii),
f(∞)=0 → f(rmax)=0 .
Let Fε(r) be the solution (to be found numericall using your own ODE solver) to our differential equation with energy ε and the initial condition Fε(rmin)=rmin-rmin2. Generally, for a random negative ε, this solution will not satisfy the boundary condition at rmax. It will only be satisfied when ε is equal one of the bound state energies of the system.
Now define an auxiliary function
M(ε) ≡ Fε(rmax) .
The shooting method is then equivalent to finding the (negative) root of the equation
M(ε) = 0 .
Find the lowest root, ε0, of the equation
M(ε) = 0
for, say, rmax=8. Plot
the resulting wave-function and compare with the exact result (which is
ε0=-1/2, f0(r)=re-r –
check this by inserting ε0 and f0(r)
into the Schredinger equation above).
Investigate the convergence of your solution towards the exact result with respect to the rmax and rmin parameters (separately) as well as with respect to the parameters acc and eps of your ODE integrator.
(1 point) Better boundary condition for the hydrogen atom problem
Now implement a more precise boundary condition for the bound states (which have ε<0), that should allow you to use a smaller rmax,
f(r → ∞) = r e-kr , (prove this)
This asymptotic form of the wave-function should be matched with your numerical solution either together with the derivative (probably the best option, since you do have the derivative from your ODE solver) or for two nearest points.
Calculate the ground state and several excited states and investigate convergence. Since this asymptotic form is exact for the ground state the latter has to converge rather immediately.