// Calculation Program for calculation of a heart curve III (Method 5),Mar. 06, 2010.



// file name:heart_curve3_e.c



#include< stdio.h>

#include< math.h>



void main(void)

{

	double x,y,a,b,c,d,k,p,q,pi;// pi is the Pi.

	double t,dt;// intermediate variable and its increment

	double tmax;// the maximum value of intermediate variable

	double xx[10001],yy[10001];// Take care of the upper limit of storage memory capacitance.

	int i,imax;



	FILE *fp;



// setting of the constant

	a=0.1;// 0.0, 0.0

	b=0.4;// 0.4, 0.4

	c=0.3;// 1.0, 0.3

	d=0.8;// 0.8, 0.8

	k=0.08;// 0.5, 0.08

	p=0.6;// 1.0, 0.6

	q=1.0;// 1.6, 1.0

	

	pi=3.1415927;

	 

// setting of the other parameters

	tmax=4.0*pi;

	dt=2*tmax/4000;// plotting interval of t



// execution of calculation

	i=0;

	for(t=-tmax;t<=tmax;t=t+dt)

		{

		i++;

		x=a*(1.-exp(-p*t*t))+c*t*t*t*t*t*exp(-q*t*t)*cos(k*t);

		y=b*(1.-exp(-p*t*t))+d*t*t*t*t*t*exp(-q*t*t)*sin(k*t);

		yy[i]=y;

		xx[i]=x;

		printf("i=%d,x=%f,y=%f\n",i,x,y);

		}

	imax=i;



	fp=fopen("heart_curve3.txt","w");

	if(fp==NULL)

		{

		printf("FILE OPEN ERROR\n");

		}

	else

		{

		for(i=1;i<=imax;i++)

			{

			fprintf(fp,"%f,%f\n",xx[i],yy[i]);

			}

		fflush(fp);

		fclose(fp);

		}

	printf("end\n");

}// the end of the program





RETURN