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,80 @@
#include <stdio.h>
#include <math.h>
#include "nrutil.h"
#define N1 2
#define N2 1
#define NTOT (N1+N2)
#define DXX 1.0e-4
int m,n;
float c2,dx,gmma;
int nn2,nvar;
float x1,x2,xf;
main() /* Program sphfpt */
{
void newt(),shootf();
int check,i;
float q1,*v1,*v2,*v;
v=vector(1,NTOT);
v1=v;
v2 = &v[N2];
nvar=NTOT;
nn2=N2;
dx=DXX;
for (;;) {
printf("input m,n,c-squared\n");
if (scanf("%d %d %f",&m,&n,&c2) == EOF) break;
if (n < m || m < 0) continue;
gmma=1.0;
q1=n;
for (i=1;i<=m;i++) gmma *= -0.5*(n+i)*(q1--/i);
v1[1]=n*(n+1)-m*(m+1)+c2/2.0;
v2[2]=v1[1];
v2[1]=gmma*(1.0-(v2[2]-c2)*dx/(2*(m+1)));
x1 = -1.0+dx;
x2=1.0-dx;
xf=0.0;
newt(v,NTOT,&check,shootf);
if (check) {
printf("shootf failed; bad initial guess\n");
} else {
printf("\tmu(m,n)\n");
printf("%12.6f\n",v[1]);
}
}
free_vector(v,1,NTOT);
return 0;
}
void load1(x1,v1,y)
float v1[],x1,y[];
{
float y1 = (n-m & 1 ? -gmma : gmma);
y[3]=v1[1];
y[2] = -(y[3]-c2)*y1/(2*(m+1));
y[1]=y1+y[2]*dx;
}
void load2(x2,v2,y)
float v2[],x2,y[];
{
y[3]=v2[2];
y[1]=v2[1];
y[2]=(y[3]-c2)*y[1]/(2*(m+1));
}
void score(xf,y,f)
float f[],xf,y[];
{
int i;
for (i=1;i<=3;i++) f[i]=y[i];
}
#undef N1
#undef N2
#undef NTOT
#undef DXX