Sie sind auf Seite 1von 2

// Bessel Function

#include <stdio.h>
#include <math.h>

int f(int k)
{
int t, s;
if(k==0 || k==1)
{
t=1;
}else
{
t=k;
do
{
t*=(k-1);
k-=1;
}while(k>=2);
}
return(t);

float j(int n, float x)


{
float t1, z, t2, acc=0.000001;
int k;
int f(int l);

t1=1.0;
z=1.0;
k=0;
do
{
t2=t1;
t1*=(pow(-1,k))*pow((x*x/(float)4),(float)k)/(float)(f(k)*f(n+k));
z+=t1;
k+=1;
}while(fabs(t1/t2)>acc);
z*=pow(x/2,(float)n);
return(z);
}

int main()
{
float x1;
int i, n=5;
int f(int k);
float j(int l, float x);

FILE *fp=NULL;
fp=fopen("bessel.txt", "w");
for(i=0; i<=n; i+=1)
{
printf("%d \t %d\n", n, i);
for(x1=0; x1<=1; x1+=0.01)
{
fprintf(fp, "%d \t %f \t %f\n", n, x1, j(n, x1));
}
}
}

Das könnte Ihnen auch gefallen