S
SS
It seems that my code locks my machine up after the " fclose(datafile);"
command
I guess I'm not following the next bit of code on properly.
Can someone help me out??
SS
============================================================================
==========
# include <stdio.h>
main ()
{
FILE *datafile;
datafile = fopen ("a:\\lab1-1-1.csv","w");
float Dt = 0.01;
float u = 1;
float Tmax = 2;
float t = 0 , e = 0, y1 = 0, y = 0;
float J = 0.02;
float k = 10;
float B = 0.5;
while (t<=Tmax)
{
e = u - y ;
y1 = y1 +(k* Dt*e);
y = y+Dt/J*(k*y1-B*y);
printf("%7.3f %7.3f \n",t,y);
fprintf(datafile,"%7.3f, %7.3f \n ", t,y);
t = t+Dt;
}
fclose (datafile);
//ok to here?
FILE *datafileb;
datafileb = fopen ("a:\\lab1-12.csv","w");
float Dt2 = 0.01;
float u2 = 1;
float Tmax2 = 2;
float t2 = 0 , e2 = 0, y12 = 0, y2 = 0;
float J2 = 0.02;
float k2 = 1;
float B2 = 0.5;
while (t2<=Tmax2);
{
e2 = u2 - y2 ;
y12 = y12 +(k2* Dt2*e2);
y2 = y2+Dt2/J2*(k2*y12-B2*y2);
printf("%7.3f %7.3f \n",t2,y2);
fprintf(datafileb,"%7.3f, %7.3f \n ", t2,y2);
t2 = t2+Dt2;
}
fclose (datafileb);
return 0;
}
command
I guess I'm not following the next bit of code on properly.
Can someone help me out??
SS
============================================================================
==========
# include <stdio.h>
main ()
{
FILE *datafile;
datafile = fopen ("a:\\lab1-1-1.csv","w");
float Dt = 0.01;
float u = 1;
float Tmax = 2;
float t = 0 , e = 0, y1 = 0, y = 0;
float J = 0.02;
float k = 10;
float B = 0.5;
while (t<=Tmax)
{
e = u - y ;
y1 = y1 +(k* Dt*e);
y = y+Dt/J*(k*y1-B*y);
printf("%7.3f %7.3f \n",t,y);
fprintf(datafile,"%7.3f, %7.3f \n ", t,y);
t = t+Dt;
}
fclose (datafile);
//ok to here?
FILE *datafileb;
datafileb = fopen ("a:\\lab1-12.csv","w");
float Dt2 = 0.01;
float u2 = 1;
float Tmax2 = 2;
float t2 = 0 , e2 = 0, y12 = 0, y2 = 0;
float J2 = 0.02;
float k2 = 1;
float B2 = 0.5;
while (t2<=Tmax2);
{
e2 = u2 - y2 ;
y12 = y12 +(k2* Dt2*e2);
y2 = y2+Dt2/J2*(k2*y12-B2*y2);
printf("%7.3f %7.3f \n",t2,y2);
fprintf(datafileb,"%7.3f, %7.3f \n ", t2,y2);
t2 = t2+Dt2;
}
fclose (datafileb);
return 0;
}