add numerical recipes library

This commit is contained in:
2025-09-12 18:55:25 +09:00
parent d4dff245bd
commit 2c75620ec9
1344 changed files with 63869 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
/* Driver for routine rtnewt */
#include <stdio.h>
#define NRANSI
#include "nr.h"
#include "nrutil.h"
#define N 100
#define NBMAX 20
#define X1 1.0
#define X2 50.0
static float fx(float x)
{
return bessj0(x);
}
static void funcd(float x,float *fn, float *df)
{
*fn=bessj0(x);
*df = -bessj1(x);
}
int main(void)
{
int i,nb=NBMAX;
float xacc,root,*xb1,*xb2;
xb1=vector(1,NBMAX);
xb2=vector(1,NBMAX);
zbrak(fx,X1,X2,N,xb1,xb2,&nb);
printf("\nRoots of bessj0:\n");
printf("%21s %15s\n","x","f(x)");
for (i=1;i<=nb;i++) {
xacc=(1.0e-6)*(xb1[i]+xb2[i])/2.0;
root=rtnewt(funcd,xb1[i],xb2[i],xacc);
printf("root %3d %14.6f %14.6f\n",i,root,fx(root));
}
free_vector(xb2,1,NBMAX);
free_vector(xb1,1,NBMAX);
return 0;
}
#undef NRANSI