Solving the Pendulum Problem with RK4 Method

  • Thread starter Thread starter MASH4077
  • Start date Start date
  • Tags Tags
    Pendulum
AI Thread Summary
The discussion revolves around a C++ simulator for a simple pendulum using the RK4 method to solve its motion. The initial issue was that the simulation was escaping quickly, attributed to using an incorrect formula for acceleration, specifically using -(g/L)*theta instead of the more accurate -g*sin(theta). Participants pointed out that the approximation holds only for small angles and that the angle should be in radians for accuracy. The original poster later realized the mistake was in not calculating acceleration based on initial conditions, leading to an incorrect value being used. After correcting this, the simulation began to function as expected.
MASH4077
Messages
12
Reaction score
0
Pendulum Problem...

Hi all,

I've written a little simulator (in C++) that demonstrates a simple pendulum swinging from right to left and back again. To simulate the motion I'm using the simple second order differential equation:

accelaration = -(g/L) * theta

and numerically integrating this using the RK4 method. However I'm having a problem in that the simulation is escaping really quickly. I just want to ask under what conditions would this happen?. I think I'm starting off the simulation with reasonable values and they are outlined below:

angle = 22.5, start angular_vel = 0.0f, init accel = calculated using above formula.

Any advice on why the simulation could be breaking so quickly is much appreciated.

Thanks.
 
Physics news on Phys.org


I am not saying that this is the problem with your program but the
acceleration cannot be g/L *theta. Maybe g*theta.
 


I may not understand the simulation, but I do have something that may be of interest. The expression you have, "acclereration = -(g/L)*theta" is an approximation. The true differential equation should have a sin(theta) rather than theta. The approximation only holds for small angles. Could this be the source of your "escaping"?

It would seem to me, that you are providing an acceleration that is greater than what nature would provide, and the larger the angle, the more inaccurate the model. Also, the approximation that sin(theta) ~ theta is only accurate if theta is given in radians. You're model therefore assumes you are using radians. Try a reasonable number for angle like 0.3 and see what you get. Or, you could change to sin(theta) and keep your numbers.
 


Yeah, Nasu is right too, but that L shouldn't really affect anything qualitatively.
 


jdog said:
It would seem to me, that you are providing an acceleration that is greater than what nature would provide, and the larger the angle, the more inaccurate the model.
Yup. I think that that is the problem for the simulation escaping. I realized this when I actually took another look at the implementation. I wasn't calculating the acceleration of the pendulum based on the initial conditions provided to the simulation, but rather I was just "feeding in" a value. I've just re-written that particular part to ensure that given the initial conditions, the correct value is assigned to the acceleration variable. Everything is now behaving as it should do.

Many Thanks.

:)
 
Hello everyone, Consider the problem in which a car is told to travel at 30 km/h for L kilometers and then at 60 km/h for another L kilometers. Next, you are asked to determine the average speed. My question is: although we know that the average speed in this case is the harmonic mean of the two speeds, is it also possible to state that the average speed over this 2L-kilometer stretch can be obtained as a weighted average of the two speeds? Best regards, DaTario
The rope is tied into the person (the load of 200 pounds) and the rope goes up from the person to a fixed pulley and back down to his hands. He hauls the rope to suspend himself in the air. What is the mechanical advantage of the system? The person will indeed only have to lift half of his body weight (roughly 100 pounds) because he now lessened the load by that same amount. This APPEARS to be a 2:1 because he can hold himself with half the force, but my question is: is that mechanical...
Some physics textbook writer told me that Newton's first law applies only on bodies that feel no interactions at all. He said that if a body is on rest or moves in constant velocity, there is no external force acting on it. But I have heard another form of the law that says the net force acting on a body must be zero. This means there is interactions involved after all. So which one is correct?
Back
Top