// [このプログラムの目的]両目の形の曲線群を描くこと,2009年11月22日(日)
// 曲線の方程式:exp(b*y**2)-(1/2)*exp{-c*(x-x0)**2}+(1/2)*exp{-c*(x+x0)**2}=exp(a)
// file name: eye_shaped_curves_aa.c
#include< stdio.h>
#include< math.h>
void main(void)
{
	double x,y,a,amax,amin,da,b,c,x0,p,q;
	int i,imax,n,nmax,j,m;
	double xmax,xmin,dx;
	double xx[2005],yy[10][1005];// 配列を格納するメモリ容量の上限に注意
	FILE *fp;
// 定数の設定
         p=0.5;
        q=0.5;
	b=1.4;// 1.4
	c=4;// 4
	x0=1.4;// 1.4
    amax=0.54;// a の最大値// 0.54
	amin=-0.56;// a の最小値// -0.56
	da=(amax-amin)/4;// パラメータ a の設定間隔
	 
// 他のパラメータ設定
	xmax=3.0;// x の最大値 // 3.0
	xmin=-xmax;// x の最小値
	dx=(xmax-xmin)/500;// x のプロット間隔
	i=0;
	n=0;
//  計算実行
	for(a=amin;a<=amax;a=a+da)
		{
		n++;
		i=0;
		for(x=-xmax;x<=xmax;x=x+dx)
			{
			i++;
			xx[i]=x;
			if(a<0&&(exp(a)+p*exp(-c*(x-x0)*(x-x0))+q*exp(-c*(x+x0)*(x+x0)))<1.0)
			{
				y=0;
			}
			else
			{
				y=sqrt((log(p*exp(-c*(x-x0)*(x-x0))+q*exp(-c*(x+x0)*(x+x0))+exp(a)))/b);
			}
			yy[n][i]=y;
			printf("i=%d,n=%d,a=%f,x=%f,y=%f\n",i,n,a,b,c,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("eye-shaped curve.txt","w");
	if(fp==NULL)
		{
		printf("FILE OPEN ERROR\n");
		}
	else
		{
		for(i=1;i<=2*imax-1;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
戻る