/*********** AE 759 HW#6********************/ //A program to create training and testing data in ASCII format //The files are: for training data: // hw6train.nna and for testing hw6test1.nna, hw6test2.nna, hw6test3.nna #include #include #include #include FILE *f1; //pointer to training data file FILE *f2; //pointer to testing data file1 FILE *f3; //pointer to testing data file2 FILE *f4; //pointer to testing data file3 int main() { float theta, theta1, theta2, l1=1, l2=1.5, h=1, x1, x2, pi=3.14159, todeg, torad; clrscr(); f1 = fopen ("hw6train.nna", "wt"); f2 = fopen ("hw6test1.nna", "wt"); f3 = fopen ("hw6test2.nna", "wt"); f4 = fopen ("hw6test3.nna", "wt"); /* "wt" means the file is a write only text file */ //printf ("t\ttorque\ttheta\tw\tx1(t+1)\tx2(t+1)\ttheta+1\tw(t+1)\n\n"); //printf ("x1(des) \t x2(des) \t theta1T \t theta2T \n \n"); //fprintf (f1,"!x1\tx2\tthe1T\tthe2T\n\n"); //variables to convert between deg and rad todeg=180/pi; torad=pi/180; //For training set for (theta1 = 45*torad; theta1<(270*torad); theta1=theta1+0.05) { for (theta2=0; theta2<(180*torad); theta2=theta2+0.05) { x1=l1*cos(theta1-(90*torad)) + l2*sin(theta2+theta1-(180*torad)); x2=h+l1*sin(theta1-(90*torad))-l2*cos(theta2+theta1-(180*torad)); if (x1>=1 && x1<=2 && x2>=0 && x2<=1) { printf ("%.2f \t %.2f \t %.2f \t %.2f \n",x1, x2, theta1*todeg, theta2*todeg); fprintf (f1, "%.2f \t %.2f \t %.2f \t %.2f \n",x1, x2, theta1*todeg, theta2*todeg); } } printf ("\n"); fprintf (f1, "\n"); } fclose (f1); //Testing SET1 for (x1=1.0; x1<=2.1; x1=x1+0.1) { x2=x1-1; printf ("%.2f \t %.2f \t 0.00 \t 0.00 \n",x1, x2); fprintf (f2, "%.2f \t %.2f \t 0.00 \t 0.00 \n",x1, x2); } fprintf (f2,"\n\n"); for (x1=1.0; x1<=2.1; x1=x1+0.1) { x2=2-x1; printf ("%.2f \t %.2f \t 0.00 \t 0.00 \n",x1, x2); fprintf (f2, "%.2f \t %.2f \t 0.00 \t 0.00 \n",x1, x2); } fclose (f2); //Testing SET2 for (theta=0; theta<=(355.1*torad); theta=theta+(5*torad)) { x1=1.5+0.40*cos(theta); x2=0.5+0.40*sin(theta); printf ("%.2f \t %.2f \t 0.00 \t 0.00 \n",x1, x2); fprintf (f3, "%.2f \t %.2f \t 0.00 \t 0.00 \n",x1, x2); } fclose (f3); //Testing SET3 for (theta=0; theta<=(355.1*torad); theta=theta+(5*torad)) { x1=1.5+0.60*cos(theta); x2=0.5+0.60*sin(theta); printf ("%.2f \t %.2f \t 0.00 \t 0.00 \n",x1, x2); fprintf (f4, "%.2f \t %.2f \t 0.00 \t 0.00 \n",x1, x2); } fclose (f4); } //end main