NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
November 25, 2017, 12:03:00 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
To live close to great minds is the best kind of education. ..."John Buchan (1875~1940 Scotticsh historian, Governor General of Canada)"
Google Bookmarks Yahoo My Web MSN Live Netscape Del.icio.us FURL Stumble Upon Delirious Ask FaceBook

Pages: [1]   Go Down
  Print  
Author Topic: Double pendulum/board:26-100-  (Read 4286 times)
0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
katia

Offline Offline

Posts: -2

«
Embed this message
on: May 21, 2010, 11:49:24 pm »

i have write the java program related to double pendulum but it seems that there is something wrong because i am changes the mass of either ball1 or ball2 ,the effect is not present,its actions remains the same and this should not happen,so could you please help me so that my program will be better.
the program that i have write is as following:

package untitled10;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;
import java.math.*;
public class Applet6 extends Applet implements Runnable,AdjustmentListener,ActionListener
{
TextField tf1;
TextField tf2;
Scrollbar sc1;
Scrollbar sc2;
Scrollbar sc3;
Scrollbar sc4;
double l1=100; // defining all the constants
double l2=70;
double m1=5;
double m2=2;
private Thread t1;
float PI=3.141592654f;
private int i;
private double g=10;
private int r1=5;
private int r2=10;
//private double l=1;
 double initial_theta1 = 30*PI/180;
 double initial_dtheta1 = 0.6;
 double initial_theta2 = 60*PI/180;
 double initial_dtheta2 = 0.7;

//private double friction = 100;
double[] t,q,dq,theta1,theta2,dtheta1,dtheta2,momentum1,momentum2;
double h=0.01;

public void init()
{


add(new Label("length1"));
sc1=new Scrollbar(0,10,4,0,200);
sc1.addAdjustmentListener(this);
add(sc1);
add(new Label("length2"));
sc2=new Scrollbar(0,10,4,0,200);
sc2.addAdjustmentListener(this);
add(sc2);
add(new Label("theta1"));
sc3=new Scrollbar(0,5,10,60,180);
sc3.addAdjustmentListener(this);
add(sc3);
add(new Label("theta2"));
sc4=new Scrollbar(0,5,10,30,180);
sc4.addAdjustmentListener(this);
add(sc4);
add(new Label("mass1"));
tf1=new TextField(2);
add(tf1);
tf1.addActionListener(this);
add(new Label("mass2"));
tf2=new TextField(2);
add(tf2);
tf2.addActionListener(this);

t= new double[10000];
theta1 = new double [10000];
dtheta1 = new double [10000];
theta2 = new double [10000];
dtheta2 = new double [10000];
momentum1 = new double [10000];//derivative of angular frequency
momentum2 = new double [10000];
t1=new Thread(this);
t1.start();
q= new double[4];
dq= new double [4];

theta1[0]=initial_theta1;
dtheta1[0]=initial_dtheta1;
theta2[0]=initial_theta2;
dtheta2[0]=initial_dtheta2;
momentum1[0]=(m1+m2)*l1*l1*dtheta1[0]+m2*l1*l2*dtheta2[0]*Math.cos(theta1[0]-theta2[0]);//initial condition
momentum2[0]=m2*l2*l2*dtheta2[0]+m2*l1*l2*dtheta1[0]*Math.cos(theta1[0]-theta2[0]);//initial condition

}
public void adjustmentValueChanged(AdjustmentEvent e)
{
l1=sc1.getValue();
repaint();
l2=sc2.getValue();
repaint();
initial_theta1=sc3.getValue();
initial_theta2=sc4.getValue();
repaint();
}
public void actionPerformed(ActionEvent e){
 m1=Integer.parseInt(tf1.getText());
 m2=Integer.parseInt(tf2.getText());
 repaint();
}

void derive() /* take the value of theta1, theta2, momentum1 and momentum 2
                          and gave us the values of dtheta1, dtheta2, dmomentum1 and dmomentum2 */

{
   dq[0]=(l2*q[2]-l1*q[3]*Math.cos(q[0]-q[1]))/(l1*l1*l2*(m1+m2*Math.sin(q[0]-q[1])*Math.sin(q[0]-q[1])));
   dq[1]=(l1*q[3]*(m1+m2)-l2*m2*q[2]*Math.cos(q[0]-q[1]))/(l1*l2*l2*m2*(m1+m2*Math.sin(q[0]-q[1])*Math.sin(q[0]-q[1])));
   dq[2]=-(m1+m2)*g*l1*Math.sin(q[0])-(((q[2]*q[3]*Math.sin(q[0]-q[1]))/(l1*l2*(m1+m2*Math.sin(q[0]-q[1])*Math.sin(q[0]-q[1])))))+((l2*l2*m2*q[2]*q[2]+l1*l1*(m1+m2)*q[3]*q[3]-l1*l2*m2*q[2]*q[3]*Math.cos(q[0]-q[1]))/(2*l1*l2*l1*l2*(m1+m2*Math.sin(q[0]-q[1])*Math.sin(q[0]-q[1]))*(m1+m2*Math.sin(q[0]-q[1])*Math.sin(q[0]-q[1]))))*Math.sin(2*(q[0]-q[1]));
   dq[3]=-m2*g*l2*Math.sin(q[1])+(((q[2]*q[3]*Math.sin(q[0]-q[1]))/(l1*l2*(m1+m2*Math.sin(q[0]-q[1])*Math.sin(q[0]-q[1])))))-((l2*l2*m2*q[2]*q[2]+l1*l1*(m1+m2)*q[3]*q[3]-l1*l2*m2*q[2]*q[3]*Math.cos(q[0]-q[1]))/(2*l1*l2*l1*l2*(m1+m2*Math.sin(q[0]-q[1])*Math.sin(q[0]-q[1]))*(m1+m2*Math.sin(q[0]-q[1])*Math.sin(q[0]-q[1]))))*Math.sin(2*(q[0]-q[1]));

}//end of derive

void eular (int i)
{
   theta1[i+1]=theta1+h*dq[0];
   theta2[i+1]=theta2+h*dq[1];
   momentum1[i+1]=momentum1+h*dq[2];
   momentum2[i+1]=momentum2+h*dq[3];
}// end of euler
public void run()
{
for(i=0;i<10000;i++)
{
t=i*h;
q[0]=theta1;
q[1]=theta2;
q[2]=momentum1;
q[3]=momentum2;
derive();
eular(i);
dtheta1=dq[0];
dtheta2=dq[1];

try
{  repaint();
t1.sleep(5);

}
catch(InterruptedException e ) {}
}
}


public void paint(Graphics g)
{
double x1,y1,x2,y2,x3,y3;
x1=getSize().width/2;
y1=200;
x2=(x1+l1*Math.sin(theta1));
y2=(y1+l1*Math.cos(theta1));
g.drawLine((int)x1,(int)y1,(int)x2,(int)y2);
g.setColor(Color.red);
g.fillOval((int)x2-r1,(int)y2-r1,2*r1,2*r1);
g.fillOval((int)x2-r2,(int)y2-r2,2*r2,2*r2);
x3=x1+l1*Math.sin(theta1)+l2*Math.sin(theta2);
y3=y1+l1*Math.cos(theta1)+l2*Math.cos(theta2);
//System.out.println(Math.cos(theta1)+"  "+Math.cos(theta2));
g.drawLine((int)x2,(int)y2,(int)x3,(int)y3);
g.setColor(Color.yellow);
g.fillOval((int)x3-r1,(int)y3-r1,2*r1,2*r1);
g.fillOval((int)x3-r2,(int)y3-r2,2*r2,2*r2);
}
}



Hope to here from you soon.
Best Regards.


Katia Smiley
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #1 on: May 22, 2010, 03:45:11 pm » posted from:Taipei,T\'ai-pei,Taiwan

The period of a pendulum does not depends on it's mass, it depends on gravity and the length of the pendulum.
Logged
Pages: [1]   Go Up
  Print  
To live close to great minds is the best kind of education. ..."John Buchan (1875~1940 Scotticsh historian, Governor General of Canada)"
 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
Double pendulum
Dynamics
Fu-Kwun Hwang 3 35929 Last post January 28, 2012, 08:45:52 pm
by Fu-Kwun Hwang
Double pendulum
Molecular Workbench
concord 0 10359 Last post August 21, 2005, 09:22:30 am
by concord
Double pendulum
dynamics
ahmedelshfie 3 7466 Last post May 20, 2010, 10:09:40 am
by ahmedelshfie
Circular double stars
Dynamics
Fu-Kwun Hwang 0 9394 Last post April 23, 2011, 11:13:10 am
by Fu-Kwun Hwang
Circular double stars
dynamics
ahmedelshfie 0 2940 Last post April 25, 2011, 07:35:35 pm
by ahmedelshfie
Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 5.091 seconds with 22 queries.since 2011/06/15