This is the web version of EJS interface
EJS version 4.3.5
1. Title=Simple Pendulum
2. Author=W. Christian and F. Esquembre remixed by lookang remixed by mattHatter
3. Keywords=pendulum, oscillation
4. Abstract=A simple pendulum model without friction or driving force. remixed by matHatter is for primary school science
5. CaptureTools=true
6. DataTools=true
7. LanguageTools=false
8. EmersionSupport=false
9. AppletColSupport=false
10. UseInterpreter=true
11. DetectedFiles=./Pendulum/cartoon building images.jpg;./Pendulum/pendulum.html;./Pendulum/pendulum_activ.html;./Pendulum/pendulum_model.html;./Pendulum/telescopic-crane-404827.jpg;
12. AuxiliaryFiles=./Pendulum/;
NameValueTypeDimension
NameValueTypeDimension
NameValueTypeDimension
NameValueTypeDimension
NameValueTypeDimension
NameValueTypeDimension
NameValueTypeDimension
NameValueTypeDimension
NameValueTypeDimension
// thetadegree = thetadegreeinput; // theta = thetadegree*Math.PI/180; t=0; //theta = Math.PI/18; // thetadegree = theta*180/Math.PI; thetadegrees = thetadegree; omega = 0; // omegatheory = omega; omegas = 0; count = 0; // ts = 0 ; j = -1;
if(mode.equals("Earth")){ g = 9.81; } else if(mode.equals("Moon")){ g = 1.67; } else if(mode.equals("Jupiter")){ g = 24.79; } else if(mode.equals("Random")){ g = 2*9.81*Math.random(); } else if(mode.equals("Outer_Space")){ g = 0.0; } else if(mode.equals("User_Defined")){ } omega = 0;

### Pendulum ODE

 Indep. Var. Increment d theta /dt= omega d omega /dt= -(g/L)*Math.sin(theta)-k*omega d thetatheory /dt= omegatheory d omegatheory /dt= -(g/L)*(thetatheory) Solver RungeKutta AbsoluteTolerance=0.001

Name:E,active=E,條件:Method:E,(誤差範圍E),stopatEvent=E
E

動作
E

Name:f,active=f,條件:Method:f,(誤差範圍f),stopatEvent=f
f

動作
f

Name:,active=,條件:Method:,(誤差範圍),stopatEvent=

動作

sc = Math.sin(theta); cs = Math.cos(theta); x= L*Math.sin(theta); y = -L*Math.cos(theta); // theory xtheory= L*Math.sin(thetatheory); ytheory = -L*Math.cos(thetatheory); //real vx = omega*L*Math.cos(theta); vy = omega*L*Math.sin(theta); v = Math.sqrt(vx*vx+vy*vy); timestring = " t = "+String.format("%8.2f\n",t) +"s"; // forces Fg = -m*g; Fgrad = Fg*cs; Fgtan = Fg*sc; Tension = m*L*omega*omega -m*g*cs; Tensionx=Tension*sc; Tensiony=-Tension*cs;
Commet:translate (angle, omega) into (x,y) coordinates
if ( Building == true&&xbuilding>=x-0.18 ) { _pause(); } else { }
// energybars KE =0.5*m*(vx*vx+vy*vy); //PE = m*g*(PEzeroy-y)*(1-Math.cos(theta)); // take reference from bottom of the swing PE = m*g*(-PEzeroy-L*Math.cos(theta)); TE = KE +PE; if ( t == 0 ) { TEs = TE; } //QEs = Fair*v*dt; //QE = QEs+QE; //TE = KE +PE +QE; QE = -KE - PE + TEs; // a reverse way to calculate QE
//alpha =(Math.atan2(vy,vx))*180/Math.PI; thetadegree = theta*180/Math.PI; omegadegree = omega*180/Math.PI;
Periodtheory = 2*Math.PI*Math.sqrt(L/g); numberofswing = Math.floor(n1/2); if (numberofswing>=20.) _pause(); // to prevent error in T1[100] array if(omega*omegas<0){ n1++; if(n1%2.==0.){ T1[nc]=t-ts; ts= t; } // else T1[nc]=t*2.;// first half period } omegas = omega; // to store value of omega /* // calculate T1 true period if( omega*omegas<0){ count=count+1; } omegas=omega;//save old value if(count==2){ j = j+1; T1[j]=t-ts[j];// period=time differences, not necessary starts from t=0 T1[0] = 0; trueT = T1[j+1]-T1[j]; ts[j]=t; count=0;//you need to reset the counter, unless you only want to calculate the first period } */
tmax = Math.max(t,tmax); // method to get the slider to remember the end max is the value

### User new position

public void newPosition () { // length is constant theta = Math.atan2(x,-y); // theory thetatheory = theta; x=L*Math.sin(theta); y=-L*Math.cos(theta); omega = 0.0; vx = 0.0; vy = 0.0; t = 0.0; _view.resetTraces(); }
Commet:Compute angle from (x,y)
EJSVIEW: Click link to view it's content
 Control variables:(testing)double,double,double,double,double,double
 title = "Pendulum Model" layout = border:0,0 visible = true location = "534,43" size = "700,533"
 position = center autoscaleX = false autoscaleY = false minimumX = xmin maximumX = xmax minimumY = ymin maximumY = ymax square = true title = "Pendulum Model" axesType = CARTESIAN1 showCoordinates = true TRmessage = %timestring% BLmessage = %dragMsg% BRmessage = %startMsg% interiorBackground = WHITE
 x = 0.23 y = -0.22 trueSize = false sizeX = 0.5 sizeY = 0.5 imageFile = "./Pendulum/telescopic-crane-404827.jpg"
 x = xbuilding y = -1.0 trueSize = false sizeX = 0.5 sizeY = 0.5 visible = Building enabledPosition = ENABLED_ANY movesGroup = true sensitivity = 10 imageFile = "./Pendulum/cartoon building images.jpg"
 numberOfElements = 3 x = new double[]{-0.07*L,0.0,0.07*L} y = new double[]{0.05*L,0.05*L,0.05*L} sizeX = L/10 sizeY = L/100 transformation = ro:60d visible = false measured = true enabledPosition = true style = RECTANGLE elementposition = SOUTH lineColor = DARKGRAY fillColor = DARKGRAY
 x = 0 y = 0 sizeX = L/5 sizeY = L/20 visible = false style = RECTANGLE elementposition = SOUTH lineColor = DARKGRAY fillColor = DARKGRAY
 x = 0 y = 0 sizeX = x sizeY = y enabledSize = false style = SEGMENT lineColor = CYAN fillColor = CYAN lineWidth = 2
 x = x y = y sizeX = m/10*L sizeY = m/10*L enabledPosition = true pressAction = _pause(); dragAction = newPosition (); _initialize(); style = ELLIPSE elementposition = CENTERED lineColor = BLACK fillColor = BLACK
 x = x y = y sizeX = vx sizeY = vy scalex = 0.1 scaley = 0.1 enabledSize = false style = ARROW lineColor = magenta fillColor = magenta lineWidth = 2
 x = x y = y sizeX = 0 sizeY = Fg scalex = 0.05 scaley = 0.05 visible = showmg lineColor = 0,100,0,255 fillColor = 0,100,0,255
 x = x+0 y = y+Fg*0.05 pixelSize = true visible = showmg text = "m*g" elementposition = NORTH lineColor = 0,100,0,255 fillColor = 0,100,0,255
 x = x y = y sizeX = Tensionx sizeY = Tensiony scalex = 0.05 scaley = 0.05 visible = showT enabledPosition = false enabledSize = false lineColor = 0,100,0,255 fillColor = 0,100,0,255
 x = x+Tensionx*0.05 y = y+Tensiony*0.05 pixelSize = true visible = showT text = "T" elementposition = WEST lineColor = 0,100,0,255 fillColor = 0,100,0,255
 inputX = x inputY = y maximumPoints = npt active = _isPlaying() norepeat = true connected = _isPlaying() lineColor = 0,0,200,100 lineWidth = 5
 x = PEzerox+L y = PEzeroy pixelSize = true visible = showPEref enabledPosition = ENABLED_Y text = "PE ref = 0 J" elementposition = SOUTH lineColor = BLUE fillColor = BLUE
 x = PEzerox y = PEzeroy sizeX = -xmin+xmax sizeY = 0 visible = showPEref enabledPosition = ENABLED_Y enabledSize = ENABLED_Y elementposition = CENTERED lineColor = BLUE
 visible = showtheory
 x = xtheory y = ytheory sizeX = m/10*L sizeY = m/10*L style = ELLIPSE elementposition = CENTERED lineColor = 0,0,200,255 fillColor = null
 x = 0 y = 0 sizeX = xtheory sizeY = ytheory enabledSize = false style = SEGMENT lineColor = CYAN lineWidth = 1
 position = south layout = VBOX borderType = LOWERED_ETCHED
 layout = HBOX
 variable = showThetaGraph text = "Show $\\theta$(t), $\\omega$(t) & $\\alpha$(t)" visible = false
 variable = v minimum = 0.0 maximum = 5 format = " v = 0.00 m/s" visible = false background = MAGENTA
 layout = HBOX visible = false
 variable = showmg background = GREEN
 variable = m*g minimum = 0.0 maximum = 9.81 format = "m*g = 0.00 N" foreground = 0,155,0,255 tooltip = "weight of the mass m due to Earth gravity field"
 layout = HBOX visible = false
 variable = showT background = GREEN
 variable = -Tension minimum = 0.0 maximum = 9.81 format = "T = 0.00 N" foreground = 0,155,0,255 tooltip = "tension force on the mass due to the string attached to it"
 position = center variable = showPEref selected = false text = "PE ref" visible = false background = BLUE foreground = WHITE tooltip = "show potential energy = 0 reference line"
 layout = HBOX
 layout = VBOX
 layout = HBOX
 position = north text = "Length =" background = CYAN
 variable = L format = " 0.00 "
 text = " m " background = CYAN
 variable = L value = 0.999991 minimum = 0.1 maximum = 1.0 ticks = 10 closest = true background = CYAN
 layout = VBOX
 layout = HBOX
 position = north text = " mass = " background = BLUE foreground = WHITE
 variable = m format = " 0.00 "
 text = " kg " background = BLUE foreground = WHITE
 variable = m minimum = 1 maximum = 7 ticks = 7 closest = true background = BLUE foreground = WHITE
 layout = VBOX
 position = center layout = HBOX
 text = " $\\theta$ = "
 variable = thetadegree format = " 00 " action = _initialize()
 text = " deg."
 variable = thetadegree value = 20 minimum = -90 maximum = 90 ticks = 19 closest = true dragaction = //thetadegree = theta*180/Math.PI; theta = thetadegree*Math.PI/180;
 layout = VBOX
 layout = HBOX
 position = north text = " g = " background = RED
 variable = g format = " 0.00 " editable = mode.equals("User_Defined")
 text = " m/s^2" background = RED
 variable = g value = 9.809607600000001 minimum = 0.0 maximum = 9.81 ticks = 7 closest = true enabled = mode.equals("User_Defined") background = RED
 options = "Earth;Moon;Jupiter;Random;Outer_Space;User_Defined" variable = mode action = _initialize()
 layout = VBOX
 position = center layout = hbox
 text = "Air resistance = " background = 64,255,64,255
 variable = k value = 0 format = 0.## editable = true action = _initialize() font = Dialog,BOLD,14 tooltip = "modeling equation Fair = k.omega example k = 0 for no air resistance, k = 1 for high resistance"
 text = "Ns/m " background = 64,255,64,255
 variable = k minimum = 0.0 maximum = 0.3 ticks = 4 closest = true background = 64,255,64,255 tooltip = "modeling equation Fair = k.omega example k = 0 for no air resistance, k = 1 for high resistance"
 layout = VBOX visible = true
 position = north layout = HBOX
 text = " Time Step: " alignment = RIGHT tooltip = "Size of time step. Increase this value to speed up the simulation."
 variable = dt tooltip = "Size of time step. Increase this value to speed up the simulation."
 position = center variable = dt minimum = 0.005 maximum = 0.1 tooltip = "Size of time step. Increase this value to speed up the simulation."
 layout = HBOX
 variable = numberofswing minimum = 0 maximum = 20 format = "=0" visible = false tooltip = "number of complete periods"
 variable = T1[nc] minimum = 0.0 maximum = T1[nc] format = "trueT = 0.00 s" visible = false tooltip = "true period T"
 layout = HBOX visible = false
 variable = Periodtheory minimum = 0.0 maximum = Periodtheory format = "T = 0.00 s" visible = showtheory tooltip = "Periodtheory"
 variable = showtheory selected = false text = "Theory Period" tooltip = "show Theory T = 2$\pi$ SQRT( L/g)"
 variable = Building text = "Building"
 variable = t minimum = 0.0 maximum = tmax format = "t = 0.00 s"
 position = east layout = HBOX
 variable = _isPaused tooltip = "Start and stop the simulation." imageOn = /org/opensourcephysics/resources/controls/images/play.gif actionOn = startMsg=null; _play(); imageOff = /org/opensourcephysics/resources/controls/images/pause.gif actionOff = _pause()
 image = "/org/opensourcephysics/resources/controls/images/stepforward.gif" action = _step();
 image = "/org/opensourcephysics/resources/controls/images/initial.gif" action = _initialize() visible = false font = Arial,BOLD,16 tooltip = to read the beginning values of the simulation and place mass at (0,0)
 image = /org/opensourcephysics/resources/controls/images/reset.gif action = _reset() tooltip = "reset simulation"
 image = "/org/opensourcephysics/resources/controls/images/wrench_monkey.gif" action = _tools.showDataTool(_view.theta_vs_time,_view.omega_vs_time); visible = false tooltip = "Show the data analysis tool."
 position = west layout = VBOX visible = showThetaGraph
 position = east autoscaleX = true autoscaleY = true yMarginPercentage = 10 titleX = "t" titleY = "$\\theta$(t), $\\omega$(t), $\\alpha$(t)"
 inputX = t inputY = theta visible = thetashow maximumPoints = 250 norepeat = true lineColor = 50,50,200,255 lineWidth = 2
 inputX = t inputY = omega visible = omegashow maximumPoints = 250 norepeat = true lineColor = 200,50,200,255 lineWidth = 2
 inputX = t inputY = -(g/L)*Math.sin(theta) visible = alphashow maximumPoints = 250 norepeat = true lineColor = 200,50,50,255 lineWidth = 2
 layout = HBOX
 position = center variable = thetashow text = "$\\theta$ (t)" background = 50,50,200,255 foreground = WHITE
 position = north variable = omegashow text = "$\\omega$(t)" background = 200,50,200,255
 position = south variable = alphashow text = "$\\alpha$(t)" background = 200,50,50,255
 position = east layout = HBOX
 position = center layout = VBOX
 variable = TEs minimum = 0.0 maximum = TEs format = "TE = 0.0 J" orientation = VERTICAL foreground = BLACK tooltip = "total energy"
 position = north layout = VBOX
 variable = PE minimum = 0.0 maximum = TEs format = "PE = 0.0 J" orientation = VERTICAL foreground = BLUE
 position = south layout = VBOX
 variable = KE minimum = 0.0 maximum = Math.abs(TEs) format = "KE = 0.0 J" orientation = VERTICAL foreground = MAGENTA
 layout = VBOX
 variable = QE minimum = 0.0 maximum = TEs format = "QE = 0.0 J" orientation = VERTICAL foreground = PINK tooltip = "thermal energy"
 position = north layout = HBOX visible = false
 position = center variable = omega format = "omega=0.00"
 variable = omegas format = "omegas=0.00"
 position = north variable = n1 format = "n1=0.0"
 position = south variable = nc format = "nc=0.0"