#include #include int main(void) {/*ニュートン方程式を解く*/ FILE *outputstream; //出力ストリーム FILE *gpstart; outputstream = fopen("data.txt","w"); //書き込みファイル if(outputstream == NULL){ printf("ファイルを開けていない\n"); exit(1); //異常終了 } double m,Fx0,Fy0; double x,y,vx,vy; double t,te,dt; double g = 9.80665; printf("条件を入れろ 質量、力x、力y\n"); scanf("%lf %lf %lf",&m,&Fx0,&Fy0); printf("初期条件,vx,vy\n"); scanf("%lf %lf",&vx,&vy); /*オイラー法*/ dt=0.01;t=0.0;te=10.0; x=0.0; y=0.0; while(t<=te){ /* xについての解*/ x = x + dt * vx; vx = vx + dt * (Fx0/m); /* yについての解*/ y = y + dt * vy; vy = vy + dt * (Fy0/m); if(y<=0.0){ break; } fprintf(outputstream,"%f %f\n",x,y); //ファイルに書く t = t + dt; } fclose(outputstream); //ファイルクローズ /*gnuplotの操作*/ gpstart = popen("gnuplot ","w"); fprintf(gpstart,"load'gp2"); pclose(gpstart); return 0; }