// [このプログラムの目的] 5種の卵型曲線を描くこと,2009年09月17日(木)
// file name: egg_shaped_curve_SUUDUKU_2b.c
// 推奨値は a=1.5, b=1.2, c=8;
#include< stdio.h>
#include< math.h>
void main(void)
{
	double x,y,a,b,c,db,bmax,bmin;
	int i,imax,n,nmax,j,m;
	double xmax,dx;
	double xx[2005],yy[10][1005];// 配列を格納するメモリ容量の上限に注意
	FILE *fp;
// 定数の設定
    a=1.5;b=1.2;c=8;
	 
// 他のパラメータ設定
	xmax=a;// x の最大値
	dx=xmax/250;// x のプロット間隔
	db=b/12;
	bmax=b+2*db+0.00001;
	bmin=b-2*db;
	i=0;
	for(x=-xmax;x<=xmax+dx/10;x=x+dx)
	{
		i++;
		n=0;
		xx[i]=x;
		for(b=bmin;b<=bmax;b=b+db)
		{
			n++;
         	        if(x>xmax)
                 	{
                		y=0;
                 	}
                	else
                	{
                		y=(1+(x+a)/c)*sqrt(1-(x/a)*(x/a))/b;
                	}
			yy[n][i]=y;
			printf("i=%d,n=%d,b=%f,x=%f,y=%f\n",i,n,b,x,y);
		}
	}
	imax=i;
	nmax=n;
	j=0;
	for(i=imax+1;i<=2*imax;i++)
	{
		j++;
		m=imax-j;
		xx[i]=xx[m];
		for(n=1;n<=nmax;++n)
		{
			yy[n][i]=-yy[n][m];
		}
	}
// 計算データのテキストファイルへの書き込み
	fp=fopen("egg-shaped curve.txt","w");
	if(fp==NULL)
	{
		printf("FILE OPEN ERROR\n");
	}
	else
	{
		for(i=1;i< 2*imax;i++)
		{
			fprintf(fp,"%f,%f,%f,%f,%f,%f\n",xx[i],yy[1][i],yy[2][i],yy[3][i],yy[4][i],yy[5][i]);
		}
		fflush(fp);
		fclose(fp);
	}
	printf("end\n");
}// the end of the program
戻る