Title: simple pendulum Post by: sithy on March 31, 2009, 08: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 Title: Re: simple pendulum Post by: FuKwun Hwang on March 31, 2009, 08:51:40 am 1. You need to select RungeKutta 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. 1.Double click download jar file to run it, 2. Right click and select open EJS model , the EJS xml source will be loaded into EJS automatically. Title: Re: simple pendulum Post by: sithy on March 31, 2009, 10: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; Title: Re: simple pendulum Post by: FuKwun Hwang on March 31, 2009, 11:25:32 am Your equations only good if dt is very small.
The error will accumulate very quickly. 1. Copy Quote x = L*Math.sin(q); to Fixed relation pagey = L*Math.cos(q); PE = m*9.8*(L+y); KE = 0.5*m*L*L*w*w; 2. remove the current evolution page 3. Add an ODE 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 RungeKutta 4th order method 7. recompile it again and it will give you correct result. Title: Re: simple pendulum Post by: lookang on March 31, 2009, 12:48:57 pm it might of of interest to browse the D:\EasyJavaSimulation\EJS_4.1_090312\EJS_4.1\workspace\source\users\murcia\fem\physics\mechanics\SimplePendulum.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 timedependent 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 etrails of my learning http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=818.0 may my XML help you too. Title: Re: simple pendulum Post by: sithy on April 08, 2009, 12: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.
PS. Looks like my xml file is not uploading.. Title: Re: simple pendulum Post by: sithy on April 08, 2009, 12:26:37 am I am unable to upload files.
Title: Re: simple pendulum Post by: FuKwun Hwang on April 08, 2009, 07:24:53 am You need to click Additional Options... to upload attached files.
The Upload new EJS simulation is for upload EJS jar file only. Title: Re: simple pendulum Post by: sithy on April 08, 2009, 10:46:38 am Thanks. I have uploaded the file.
Title: Re: simple pendulum Post by: FuKwun Hwang on April 08, 2009, 01: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. Title: Re: simple pendulum Post by: sithy on April 08, 2009, 08: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.
