⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sphfpt.c

📁 Numerical Recipes Software 提供的算法子程序集
💻 C
字号:
#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
/* (C) Copr. 1986-92 Numerical Recipes Software . */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -