Thread: Runge Kutta IV project problem

  1. #16
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    I don't have time to try your code now, but this problem should be the same as a pendulum (massless rod of length R with point mass at end of rod). You can do a web search to find exact equations for pendulums and compare the results to your programs output.

  2. #17
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    If I compile your program from post #5 I get the following warnings:
    Code:
    $ gcc -Wall -Wextra -ggdb3 foo.c -lm
    foo.c: In function ‘fun’:
    foo.c:73:19: warning: unused parameter ‘x0’ [-Wunused-parameter]
    foo.c: In function ‘main’:
    foo.c:107:5: warning: passing argument 5 of ‘vrk4’ from incompatible pointer type [enabled by default]
    foo.c:20:10: note: expected ‘void (*)(double,  double *, double *)’ but argument is of type ‘double (*)(double,  double *, double *)’
    foo.c:112:5: warning: passing argument 5 of ‘vrk4’ from incompatible pointer type [enabled by default]
    foo.c:20:10: note: expected ‘void (*)(double,  double *, double *)’ but argument is of type ‘double (*)(double,  double *, double *)’
    foo.c:99:11: warning: unused variable ‘j’ [-Wunused-variable]
    foo.c:99:9: warning: unused variable ‘p’ [-Wunused-variable]
    foo.c:98:12: warning: unused variable ‘ss’ [-Wunused-variable]
    foo.c:94:12: warning: unused variable ‘F’ [-Wunused-variable]
    foo.c:135:1: warning: control reaches end of non-void function [-Wreturn-type]
    foo.c: In function ‘fun’:
    foo.c:81:1: warning: control reaches end of non-void function [-Wreturn-type]
    You need to fix them before you can check whether your program produces a correct result or not.

    Bye, Andreas

  3. #18
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    Based on the math from pendulums, since your function for angular acceleration is g sin(theta) / r, then if the initial condition is theta = pi/2 and omega = 0, then the time it should take to cycle back to pi/2 will be about 1.18 * 2 * pi * sqrt(r / g). In your case, with r = 0.5 and g = 9.81, the cycle time should be about 1.674 seconds. You can use this information to confirm your results.

  4. #19
    Registered User
    Join Date
    Jan 2013
    Posts
    15
    I still can't get through the -1.#IND00 ... i'm not too familiar with programming at all, and I can't find the problem computer does... I changed the quantities of thetha and omega but still can't get the program working :/

  5. #20
    Registered User
    Join Date
    Jan 2013
    Posts
    15
    okay, i have another question. I got through the problem, the program is working correctly, but i wonder if the mechanic energy should be constant?

  6. #21
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    Quote Originally Posted by achikha View Post
    okay, i have another question. I got through the problem, the program is working correctly, but i wonder if the mechanic energy should be constant?
    It should be constant. I wrote a test program, same time step as yours, .01, but with different initial conditions, theta = pi/2 and omega = 0, getting a consistent total energy of 4.9050.

    Note since I consider positive omega to be counter clockwise, my function for angular acceleration would be equivalent to the negative of yours: F[1]=-(g*sin(y0[0])/R), and theta goes from +pi/2 to 0 to -pi/2 and back (in about 1.674 seconds).
    Last edited by rcgldr; 06-16-2013 at 05:50 AM.

  7. #22
    Registered User
    Join Date
    Jan 2013
    Posts
    15
    wow, can you help me out with total energy formula? because mine ( m*(fabs(y1[1])*R)*(fabs(y1[1])*R)/2.)+m*g*R*cos(y1[0]) doesn't work as a constant...

  8. #23
    Registered User
    Join Date
    Jan 2013
    Posts
    15
    and also, how to calculate angular path? not angular position which right now is calculated.

  9. #24
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    Quote Originally Posted by achikha View Post
    wow, can you help me out with total energy formula? because mine ( m*(fabs(y1[1])*R)*(fabs(y1[1])*R)/2.)+m*g*R*cos(y1[0]) doesn't work as a constant...
    You had it correct before, and you don't need the abs since you're squaring the y1[1] term:

    m*y1[1]*y1[1]*R*R/2. + m*g*R*(1. - cos(y1[0]))

    Quote Originally Posted by achikha View Post
    and also, how to calculate angular path? not angular position which right now is calculated.
    I'm not sure what you mean by angular path. The path is R theta (a circular path).
    Last edited by rcgldr; 06-16-2013 at 03:00 PM.

  10. #25
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    Try setting your time step smaller, like "t = .0335;" . This goes through 2 cycles in 100 steps: (~ 2 * 1.674 seconds / 100).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Runge Kutta Projectile Problem
    By meadmead in forum C Programming
    Replies: 2
    Last Post: 11-25-2011, 02:25 PM
  2. Runge Kutta 4
    By rhenley in forum C Programming
    Replies: 20
    Last Post: 05-23-2010, 01:39 PM
  3. Runge-Kutta Problem
    By nickbrown05 in forum C Programming
    Replies: 10
    Last Post: 11-13-2008, 11:00 AM
  4. Runge Kutta for electron trajectories
    By QueenB in forum C Programming
    Replies: 1
    Last Post: 05-03-2007, 08:12 PM
  5. Simple problem with a Runge-Kutta program
    By civil25 in forum C Programming
    Replies: 10
    Last Post: 04-25-2007, 12:07 PM