double zriddrp480(double (*func)(double,int,double[],double[],double[],int), double x1, double x2, double xacc, int match, double V[], double r[], double dr[], int N)Return value:
- solution x to equation f(x)=0
Input:
- func: subroutine which returns the values f(x)
- x1, x2: bracket on desired solution, x1<x<x2
- xacc: accuracy of desired solution
- match: dummy variable (needed for Problem 4)
- V[]: potential on corresponding grid points, r[]
- r[], dr[], N: standard grid information
A much more powerful algorithm for finding zeros of a function is Ridder's method. This method works with the same basic information as the bisection method and so can be called in exactly the same way, but requires far fewer function evaluations to reach the same accuracy.
Make the same modifications to zriddr() that you made to rtbis() to produce a function of the above prototype in ``p480.c'' and ``p480.h''. Be sure print out the final number of iterations needed and final function value.
Finally, the numerical recipes routine zriddr() also has a small bug: for wildly varying functions such as func_Schrodinger(), zriddr() sometimes returns too early. To fix this, replace the code fragment
in zriddrp480() withif (fabs(xnew-ans) <= xacc) ...
if (fabs(xl-xh) <= xacc) ... .
To test your function, uncomment out the lines labeled ``Test of zriddrp480()'' in ``Edebug.c'', and verify that zriddrp480() returns the same results as rtbisp480(), but with far fewer function calls.