### Author Topic: simple pendulum  (Read 15894 times)

#### sithy

• Newbie
• • Posts: 10 ##### simple pendulum
« on: March 31, 2009, 09:44:49 am »
In an attempt to learn EJS, I started to do simple pendulum simulation since there are a lots of those already available over the internet. I am starting off with the differential equation, a = -(g/L) sin q where a is the angular acceleration and q is the angle of the string with respect to the vertical. My amplitude drops with time. Note that I have not introduced any damping. My plot of w vs. q are ellipse which spiral down towards the center with time (expected). I have googled to find solution to exact solution to this equation.

I saw one of your simple pendulums. I did not see its source. Are you assuming small angle oscillations?

Thanks

#### Fu-Kwun Hwang

• Hero Member
•     • • Posts: 3062 ##### Re: simple pendulum
« Reply #1 on: March 31, 2009, 09:51:40 am »
1. You need to select Runge-Kutta 4th order numerical method in the evolution page.
2. It depends on how you wrote the evolution page. Please upload your ejs xml source as attachement.

If you want to open the xml source for EJS simulation download at this  web site.
2. Right click and select open EJS model , the EJS xml source will be loaded into EJS automatically.

#### sithy

• Newbie
• • Posts: 10 ##### Re: simple pendulum
« Reply #2 on: March 31, 2009, 11:50:01 am »
I did not use the differential equations technique. My Evaluation page looks like this:

a =-g*Math.sin(q)/L;
q -= w*dt - 0.5 * a * dt*dt;
a = -g*Math.sin(q)/L;
w-= a*dt;
t +=dt;
x = L*Math.sin(q);
y = -L*Math.cos(q);
PE = m*9.8*(L+y);
KE = 0.5*m*L*L*w*w;

#### Fu-Kwun Hwang

• Hero Member
•     • • Posts: 3062 ##### Re: simple pendulum
« Reply #3 on: March 31, 2009, 12:25:32 pm »
Your equations  only good if dt is very small.
The error will accumulate very quickly.

1. Copy
Quote
x = L*Math.sin(q);
y = -L*Math.cos(q);
PE = m*9.8*(L+y);
KE = 0.5*m*L*L*w*w;
to Fixed relation page
2. remove the current evolution page
At the top two text field enter t and dt

4 .enter q at the left first column (it will displayed as dq/dt). enter w at the right column
to set up dq/dt=w , this will tell EJS to calculate new q(t+dt) from q(t) and w
5. enter another relation to get

dw/dt = -g*Math.sin(q)/L;

6. select Runge-Kutta 4th order method
7. re-compile it again and it will give you correct result.

#### lookang

• Hero Member
•     • • Posts: 1772
• http://weelookang.blogspot.com ##### Re: simple pendulum
« Reply #4 on: March 31, 2009, 01:48:57 pm »
it might of of interest to browse the D:EasyJavaSimulationEJS_4.1_090312EJS_4.1workspacesourceusersmurciafemphysicsmechanicsSimplePendulum.xml

i think it has useful tips for modeling pendulum.

Description: Pendulum
A simple pendulum is a physical abstraction that considers a point mass m that oscillates in a vertical plane at the end of a rod of length L and negligible mass.

If we consider the force exerted by gravity on the mass as constant, g, the motion of a simple pendulum can be modeled by a second order ordinary differential equation.
The equation includes a friction force, with b as friction coefficient, and a time-dependent external torque of the form A*sin(F*t), which drives the motion. Typically, the pendulum starts oscillating at time t=0, from a given angle with zero initial angular velocity.

Evolution equation:
d(theta)/dt = omega
d(omega)/dt =-g/L * Math.sin(theta) + (-b*omega+torque(t))/(m*L*L)

Custom:
public double torque (double time) {
return amplitude*Math.sin(frequency*time);
}

I would delete the torque part if you want a simple pendulum with no external torque.

Evolution equation:
d(theta)/dt = omega
d(omega)/dt =-g/L * Math.sin(theta)

I also journeyed on learning with e-trails of my learning
http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=818.0
« Last Edit: March 31, 2009, 01:51:26 pm by lookang »

#### sithy

• Newbie
• • Posts: 10 ##### Re: simple pendulum
« Reply #5 on: April 08, 2009, 01:24:44 am »
Thanks for your responses. I have attached a file below. Please have a look at it. Try to increase the length by simply typing a number in the Length field and hitting the 'enter' key. Take a look at the pendulum. When length reach large values (eg. L = 2.0 m), the fixed end of the string begins to oscillate as well. I could not figure out why this is. In the properties of string, I have set x = y = 0 (so they are fixed !) and Pos(x) and Pos (y) are functions of x and y.  Could you able to tell me why the fixed end of the string is moving for L >>. I am trying to understand EJS. Thank you.

#### sithy

• Newbie
• • Posts: 10 ##### Re: simple pendulum
« Reply #6 on: April 08, 2009, 01:26:37 am »
I am unable to upload files.

#### Fu-Kwun Hwang

• Hero Member
•     • • Posts: 3062 ##### Re: simple pendulum
« Reply #7 on: April 08, 2009, 08:24:53 am »
The Upload new EJS simulation is for upload EJS jar file only.

#### sithy

• Newbie
• • Posts: 10 ##### Re: simple pendulum
« Reply #8 on: April 08, 2009, 11:46:38 am »
Thanks. I have uploaded the file.

#### Fu-Kwun Hwang

• Hero Member
•     • • Posts: 3062 ##### Re: simple pendulum
« Reply #9 on: April 08, 2009, 02:00:17 pm »
The problem is due to that
Autoscale X and Autoscale Y of the drawingPanel "Simple_Pendulum" were set to  true as default.
Even the default range was -1 to 1.
But when the x,y is smaller than -1 , EJS will change the scale so that it will fit into the range automatically (because it was set to autoscale)

You can set the Autoscale X and Autoscale Y to false
But you will need to change ymin and ymax to larger value , e.g. -1.5 to 1.5 or larger otherwise, it will be drawn outside the simulation region.

You do not need to set action to _paly() in the texfield region. unless it was not running initially, and you want to start the simulation when user enter new value.

For those traces in the plotting panel, I would suggest you set Max Points to a variable: e.g. maxpts
and define maxpts = 500(as integer) , then only the last 500 points will be shown in the trace.
Otherwise, the time scale will be changing all the time in the plottingPanel.

#### sithy

• Newbie
• • Posts: 10 ##### Re: simple pendulum
« Reply #10 on: April 08, 2009, 09:55:58 pm »
Thank you. I have some free time these days. I found EJS very interesting and decided to create some simulations. Your site is very helpful. Thanks.

#### cyberops21

• Newbie
• • Posts: 1 ##### Re: simple pendulum
« Reply #11 on: January 28, 2020, 05:15:36 pm »
these are some really helpful replies 