math - Modelling a Pendulum in C -


this code attempting while loop model pendulum swing, values produced don't seem me:

#include <stdio.h> #include <math.h> #define pi 3.14159265  main() {     float theta = 0;   // initial value angle     float omega = 0.2; // initial value angular speed     float time = 0;    // initial time     float dt = 0.01;   // time step      while (theta < 2 * pi && -2*pi) {         time = time + dt;         theta = theta + omega*dt;          printf("theta=%i, omega=%i, time=%i, , dt=%i\n", theta, omega, time, dt);     }     system("pause"); } 

how can modify more helpful? while condition have use should stop when pendulum has made 1 revelation either forwards or backwards (-2pi or 2pi). need use formula 'omega=omega-(g/l)dtsin(theta)' , not make assumption theta approximately equals sin(theta).

  1. while(theta <2*pi&&-2*pi)

    in c if want combine multiple expressions can combine them using logical operators

    while((theta < 2 * pi) && (theta > -2 * pi))   

    ps- no physics expert. change conditions per requirement


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -