/* Soluzione numerica del problema del punto materiale lanciato verticalmente */ #include #include #include int main(int argc, char *argv[]) { float v0, theta, vx, vy, vxm, vym, ax, ay, dt; float t=0, x = 0., y = 0.; const float grad2rad = acos(-1) / 180.; // conversione gradi->rad const float g = 9.8; // m/s^2 // Att: g è ... g, mentre ay = -g !! /* legge i parametri del lancio (v0, theta e dt) da riga di comando, ad esempio ./lancio_2D 10 45 0.01 */ if (argc < 4) { puts("Devi dare anche velocità iniziale (m/s), angolo (gradi) e dt (s)"); return 0; } v0 = .... ; theta = .... ; dt = .....; printf("Parametri del lancio: v0 = %.2f m/s, theta = %.0f gradi\n", v0, theta); printf("Discretizzazione: dt = %f s\n", dt); vx = .... ; // componenti della velocità vy = .... ; printf("\nVelocità iniziale: (%.2f, %.2f) m/s\n", vx, vy); ax = 0.; // anche se è nulla, può servire per altri casi ay = -g; while (y >= 0) { vxm = vx + ax * dt/2; // velocita' media: (v + (v+a*dt))/2 vym = .... ; vx += ax * dt; // velocita' dopo intervallo dt vy += .... ; x += .... ; /* posizione dopo intervallo dt in cui il corpo si e' mosso con v media vxm */ y += .... ; // idem lungo y t += dt; // tempo dopo intervallo dt printf(" t=%.3f s; x=%.2f m, y=%.2f m; vx=%.2f m/s, vy=%.2f m/s\n", t, x, y, vx, vy); } return 0; }