// ************************************** // ** Computing II Lab. session 3 (PJM)** // ** Solution of coupled differential ** // ** equations using Euler's method ** // ************************************** #include #include float d_omega_dt(float); int main(void) { FILE *fp; float omega[2000], theta[2000],time=0.0,time_step=.04; int t; theta[0]=M_PI/4.0; // Starting angle omega[0]=0.00; // Starting velocity is 0 rad/s fp=fopen("pendulum.dat","w"); for (t=0;t<1999;t++) { omega[t+1]=omega[t]+d_omega_dt(theta[t])*time_step; theta[t+1]=theta[t]+(time_step*omega[t]); fprintf(fp, "%f,%.2f \n",time,theta[t]*180/M_PI); time+=time_step; } fclose(fp); } // Function to calculate dv/dt using // formula dv/dt = -(g/l)*sin(theta) float d_omega_dt(float angle) { float g=9.8; float l=9.8; float dveldt; dveldt=-(g/l)*sin(angle); return(dveldt); }