Ejemplo n.º 1
0
int main(void)
{
	int i;
	float b1,b2,b3,b4,xf=X1+HTOT,*y,*yout,*dydx;

	y=vector(1,NVAR);
	yout=vector(1,NVAR);
	dydx=vector(1,NVAR);
	y[1]=bessj0(X1);
	y[2]=bessj1(X1);
	y[3]=bessj(2,X1);
	y[4]=bessj(3,X1);
	derivs(X1,y,dydx);
	b1=bessj0(xf);
	b2=bessj1(xf);
	b3=bessj(2,xf);
	b4=bessj(3,xf);
	printf("First four Bessel functions:\n");
	for (i=5;i<=50;i+=5) {
		mmid(y,dydx,NVAR,X1,HTOT,i,yout,derivs);
		printf("\n%s %5.2f %s %5.2f %s %2d %s \n",
			"x=",X1," to ",X1+HTOT," in ",i," steps");
		printf("%14s %9s\n","integration","bessj");
		printf("%12.6f %12.6f\n",yout[1],b1);
		printf("%12.6f %12.6f\n",yout[2],b2);
		printf("%12.6f %12.6f\n",yout[3],b3);
		printf("%12.6f %12.6f\n",yout[4],b4);
		printf("\nPress RETURN to continue...\n");
		(void) getchar();
	}
	free_vector(dydx,1,NVAR);
	free_vector(yout,1,NVAR);
	free_vector(y,1,NVAR);
	return 0;
}
Ejemplo n.º 2
0
int main(void)
{
	int i,j;
	float h,x=1.0,*y,*dydx,*yout;

	y=vector(1,N);
	dydx=vector(1,N);
	yout=vector(1,N);
	y[1]=bessj0(x);
	y[2]=bessj1(x);
	y[3]=bessj(2,x);
	y[4]=bessj(3,x);
	derivs(x,y,dydx);
	printf("\n%16s %5s %12s %12s %12s\n",
		"Bessel function:","j0","j1","j3","j4");
	for (i=1;i<=5;i++) {
		h=0.2*i;
		rk4(y,dydx,N,x,h,yout,derivs);
		printf("\nfor a step size of: %6.2f\n",h);
		printf("%12s","rk4:");
		for (j=1;j<=4;j++) printf(" %12.6f",yout[j]);
		printf("\n%12s %12.6f %12.6f %12.6f %12.6f\n","actual:",
			bessj0(x+h),bessj1(x+h),bessj(2,x+h),bessj(3,x+h));
	}
	free_vector(yout,1,N);
	free_vector(dydx,1,N);
	free_vector(y,1,N);
	return 0;
}
Ejemplo n.º 3
0
void main ()
{
	real_t bessj0(real_t);
	real_t x;

	x=1.0;
	printf("BESSJ0 delivers:  %2.0f    %e\n",x,bessj0(x));
}
Ejemplo n.º 4
0
void bessy01(real_t x, real_t *y0, real_t *y1)
{
	if (x < 8.0) {
		int i;
		real_t bessj0(real_t);
		real_t bessj1(real_t);
		real_t z,z2,c,lnx,b0,b1,b2;
		static real_t ar1[15]={0.164349e-14, -0.8747341e-13,
			0.402633082e-11, -0.15837552542e-9, 0.524879478733e-8,
			-0.14407233274019e-6, 0.32065325376548e-5,
			-0.563207914105699e-4, 0.753113593257774e-3,
			-0.72879624795521e-2, 0.471966895957634e-1,
			-0.177302012781143, 0.261567346255047,
			0.179034314077182, -0.274474305529745};
		static real_t ar2[15]={0.42773e-15, -0.2440949e-13,
			0.121143321e-11, -0.5172121473e-10, 0.187547032473e-8,
			-0.5688440039919e-7, 0.141662436449235e-5,
			-0.283046401495148e-4, 0.440478629867099e-3,
			-0.51316411610611e-2, 0.423191803533369e-1,
			-0.226624991556755, 0.675615780772188,
			-0.767296362886646, -0.128697384381350};
		c=0.636619772367581;
		lnx=c*log(x);
		c /= x;
		x /= 8.0;
		z=2.0*x*x-1.0;
		z2=z+z;
		b1=b2=0.0;
		for (i=0; i<=14; i++) {
			b0=z2*b1-b2+ar1[i];
			b2=b1;
			b1=b0;
		}
		*y0 = lnx*bessj0(8.0*x)+z*b1-b2-0.33146113203285e-1;
		b1=b2=0.0;
		for (i=0; i<=14; i++) {
			b0=z2*b1-b2+ar2[i];
			b2=b1;
			b1=b0;
		}
		*y1 = lnx*bessj1(8.0*x)-c+x*(z*b1-b2+0.2030410588593425e-1);
	} else {
		void besspq0(real_t, real_t *, real_t *);
		void besspq1(real_t, real_t *, real_t *);
		real_t c,cosx,sinx,p0,q0,p1,q1;
		c=0.797884560802865/sqrt(x);
		besspq0(x,&p0,&q0);
		besspq1(x,&p1,&q1);
		x -= 0.706858347057703e1;
		cosx=cos(x);
		sinx=sin(x);
		*y0 = c*(p0*sinx+q0*cosx);
		*y1 = c*(q1*sinx-p1*cosx);
	}
}
Ejemplo n.º 5
0
int main(void)
{
	int i,j;
	float eps,hdid,hnext,htry,x=1.0,*y,*dydx,*dysav,*ysav,*yscal;

	y=vector(1,N);
	dydx=vector(1,N);
	dysav=vector(1,N);
	ysav=vector(1,N);
	yscal=vector(1,N);
	ysav[1]=bessj0(x);
	ysav[2]=bessj1(x);
	ysav[3]=bessj(2,x);
	ysav[4]=bessj(3,x);
	derivs(x,ysav,dysav);
	for (i=1;i<=N;i++) yscal[i]=1.0;
	htry=0.6;
	printf("%10s %11s %12s %13s\n","eps","htry","hdid","hnext");
	for (i=1;i<=15;i++) {
		eps=exp((double) -i);
		x=1.0;
		for (j=1;j<=N;j++) {
			y[j]=ysav[j];
			dydx[j]=dysav[j];
		}
		rkqs(y,dydx,N,&x,htry,eps,yscal,&hdid,&hnext,derivs);
		printf("%13f %8.2f %14.6f %12.6f \n",eps,htry,hdid,hnext);
	}
	free_vector(yscal,1,N);
	free_vector(ysav,1,N);
	free_vector(dysav,1,N);
	free_vector(dydx,1,N);
	free_vector(y,1,N);
	return 0;
}
Ejemplo n.º 6
0
int main(void)
{
	int i,nbad,nok;
	float eps=1.0e-4,h1=0.1,hmin=0.0,x1=1.0,x2=10.0,*ystart;

	ystart=vector(1,N);
	xp=vector(1,200);
	yp=matrix(1,10,1,200);
	ystart[1]=bessj0(x1);
	ystart[2]=bessj1(x1);
	ystart[3]=bessj(2,x1);
	ystart[4]=bessj(3,x1);
	nrhs=0;
	kmax=100;
	dxsav=(x2-x1)/20.0;
	odeint(ystart,N,x1,x2,eps,h1,hmin,&nok,&nbad,derivs,rkqs);
	printf("\n%s %13s %3d\n","successful steps:"," ",nok);
	printf("%s %20s %3d\n","bad steps:"," ",nbad);
	printf("%s %9s %3d\n","function evaluations:"," ",nrhs);
	printf("\n%s %3d\n","stored intermediate values:    ",kount);
	printf("\n%8s %18s %15s\n","x","integral","bessj(3,x)");
	for (i=1;i<=kount;i++)
		printf("%10.4f %16.6f %14.6f\n",
			xp[i],yp[4][i],bessj(3,xp[i]));
	free_matrix(yp,1,10,1,200);
	free_vector(xp,1,200);
	free_vector(ystart,1,N);
	return 0;
}
Ejemplo n.º 7
0
static float fx(float x)
{
	return bessj0(x);
}
Ejemplo n.º 8
0
float func(float x)
{
	return bessj0(x);
}