/* numerov.cc: mumerov method to find eigenvalues and eigenfunctions of a particle in a potential well. code checks continuity of psi derivative. you need to set the parity of the solutions whose energy eigenvalues you are seeking. */ #include #include #include #include using namespace std; const double V0 = -83.0; // depth of potential well in MeV const double E_min = -55.0; // energy band to find const double E_max = -20.0; // energy eigenvalue const double eps = 1E-8; // matching tolerance double h = 0.004; // step size // well is assumed 4 fm wide // universe is 8 fm wide // 2000 total steps double Parity = -1.0; // odd/even parity = -1/1 double k2(int i, double E); /* returns potential at x */ double diff(double E, double& left, double& right); /* difference of psi + left/right derivates */ void write_data(double E); /* saved data for final plot */ int main() { double E_mid, E_lo, E_hi; int i=0; // counter for iterations int MAX_iter = 200; // max number of iterations double left_deriv = 0.0; double right_deriv = 0.0; E_lo = E_min; E_hi = E_max; if (Parity ==1) cout << " ----> Even parity solution(s) selected." << endl; else cout << " ----> Odd parity solution(s) selected." << endl; while(fabs(diff(E_mid, left_deriv, right_deriv))>eps && i <= MAX_iter){ E_mid =(E_lo + E_hi)/2.0; // first guess for energy eigenvale if (GSL_SIGN(diff(E_mid, left_deriv, right_deriv))* GSL_SIGN(diff(E_hi, left_deriv, right_deriv)) < 0.0) E_lo = E_mid; // the bisection algorithm else E_hi = E_mid; ++i; } if (!(i < MAX_iter )) cout << "\n ----> WARNING: max number of iterations exceeded." << endl; else { if (!(GSL_SIGN(left_deriv)==GSL_SIGN(right_deriv))) cout << "psi derivatives DO NOT match. no solution." << endl; else{ cout << "Eigenvalue E = " << E_mid << " MeV." <