Sunteți pe pagina 1din 8

Y

m3 (x3,y3) m4 (x4,y4)
mi (xi,yi)

m5 (x5,y5)

m1 (x1,y1)
v v v v
ry v r = r12 = r2 − r1
r1
m2 (x2,y2)
v
r2
X

x r
v
r1 = x1 xˆ + y1 yˆ
v
r2 = x2 xˆ + y2 yˆ
v v v
r = r2 − r1 = (x2 − x1 )xˆ + ( y2 − y1 ) yˆ
rx = (x2 − x1 )
ry = ( y2 − y1 )
v
r = rx xˆ + ry yˆ
r = rx2 + ry2

v Gm1 m2
F12 = 2

r ,
v
r
rˆ = , is a unit vector
r
v Gm1 m2 v
F12 = 3
r
r
v Gm1 m2
F12 = 3
(rx xˆ + ry yˆ )
r
v  Gm1 m2   Gm1 m2 
F12 =  r  xˆ +  r  yˆ
 r3 x
  r3 y

   

v  Gm1 m2   Gm m
 xˆ +  1 2

 yˆ
F12 = r r
 r 2 + r 2 32 x   r 2 + r 2 32 y 
( ) ( )
 x y   x y 
rp = r =3
(r x
2
+r 2
y ) = (r
3
x
2 2
+r
y )
3
2

co = Gm1 m2

v  co   co 
F12 =  rx  xˆ +  ry  yˆ
r  r 
 p   p 

Components of vector;
 co   co 
Fx12 =  rx , Fy12 =  ry 
r  r 
 p   p 
v
Magnitude of F12 ;

F12 = (F ) + (F )
x12
2
y12
2

Direction;

−1
Fy12
θ = tan
Fx12

For n total number of particles;


v v v v v v
F1net = F12 + F13 + F14 + F15 + ............F1n

v n v
F1net = ∑ F1i
i =2
n n
Fx1net = ∑ Fx1i Fy1net = ∑ Fy1i
,
i =2 i =2
Y

m3 (0.2,5.5)
7.5 kg
5 m5 (4.2,4.5)

6.6 kg
4

3 m4 (5.2,2.5)
m1 (1.2,2.5)
2.5 kg 9.2 kg
2
m2 (1.5,1.5)
1 1.5 kg

X
1 2 3 4 5

Given m1 to m5 and their coordinates are as above. Calculate the gravitational force at m1 due to
m2, m3, m4 and m5.

m[1]=2.5; x[1]=1.2; y[1]=2.5;


m[2]=1.5; x[2]=1.5; y[2]=1.5;
m[3]=7.5; x[3]=0.2; y[3]=5.5;
m[4]=9.2; x[4]=5.2; y[4]=2.5;
m[5]=6.6; x[5]=4.2; y[5]=4.5;

The algorithm:

1. Declare the class/method to be used


2. Declare and assign all variables to be used
3. Initialize value to all respective variables
4. Decide on which mass the gravitational force to be calculated
(e.g on mj where j=1)
5. Set fx=0 and fy=0
6. Start the loop from j=2 to j=5 to calculate the summation of fx and fy
7. Resolve the gravitational force into unit vector (2D Cartesian coordinate)
v v v
8. Calculate the mass vector position: r = r2 − r1 = ( x2 − x1 )xˆ + ( y2 − y1 ) yˆ
Therefore: rx = x[j]-x[1] and ry = y[j]-y[1]
9. Define/assign all respective equations to be used:

v  Gm1 m2   Gm m
  1 2

 yˆ
F = ˆ
3 rx x + 3 ry
 r2 + r2 2   r2 + r2 2 
( ) ( )
 x y   x y 
rp = r =3
(r x
2
+r2
y ) = (r
3
x
2
+ ry2 )
3
2

co = Gm1 m2

v  co   co 
F =  rx  xˆ +  ry  yˆ
r  r 
 p   p 
10. Calculate the summation of fx and fy until mj (j=2 to j=5) :
fx = fx + co (rx/rp)
fy = fy + co(ry/rp)

11. Calculate the magnitude of the gravitational force: F = (Fx )2 + (Fy )2


Fy
12. Calculate the direction of F; θ = tan−1
Fx
13. Print the results
Source code GravityAttract05a.java
/* Java class for calculating the resultant force on an object m1
due to for other objects m2, m3, m4, and m5
*/

import static java.lang.Math.*;

public class GravityAttract05a


{
public static void main(String args[])
{
double[] m = new double[6]; // mass of object
double[] x = new double[6]; // x-coor of object
double[] y = new double[6]; // y-coor of object
double f; // resultant force
double fx,fy; // x & y component of force
double rx, ry, rp, co, G;
int j;

G = 6.67e-11;
m[1]=2.5; x[1]=1.2; y[1]=2.5;
m[2]=1.5; x[2]=1.5; y[2]=1.5;
m[3]=7.5; x[3]=0.2; y[3]=5.5;
m[4]=9.2; x[4]=5.2; y[4]=2.5;
m[5]=6.6; x[5]=4.2; y[5]=4.5;

fx = 0.0;
fy = 0.0;
for(j=2; j<=5; j++)
{
rx = x[j]-x[1];
ry = y[j]-y[1];
rp = pow((rx*rx+ry*ry),1.5); // (rx^2 + ry^2) raised to the power of 3/2
co = G*m[1]*m[j];
fx = fx + co*rx/rp;
fy = fy + co*ry/rp;
}
f = sqrt(fx*fx + fy*fy);
System.out.printf("\n\tThe force on m[1] due to the other masses is %e N\n\n",f);
}
}
Source code GravityAttract06a.java
/* Java class for calculating the resultant force on each object
(on m1 through m5)
*/

import static java.lang.Math.*;

public class GravityAttract06a


{
public static void main(String args[])
{
double[] m = new double[6]; // mass of object
double[] x = new double[6]; // x-coor of object
double[] y = new double[6]; // y-coor of object
double f; // resultant force
double fx,fy; // x & y component of force
double rx, ry, rp, co, G, dirf,angdirf;
int j, mi;

G = 6.67e-11;
m[1]=2.5; x[1]=1.2; y[1]=2.5;
m[2]=1.5; x[2]=1.5; y[2]=1.5;
m[3]=7.5; x[3]=0.2; y[3]=5.5;
m[4]=9.2; x[4]=5.2; y[4]=2.5;
m[5]=6.6; x[5]=4.2; y[5]=4.5;

for (mi=1; mi<=5; mi++)


{
fx = 0.0;
fy = 0.0;
for(j=1; j<=5; j++)
{
if (j!=mi)
{
rx = x[j]-x[mi];
ry = y[j]-y[mi];
rp = pow((rx*rx+ry*ry),1.5); // (rx^2 + ry^2) raised to the power of 3/2
co = G*m[mi]*m[j];
fx = fx + co*rx/rp;
fy = fy + co*ry/rp;
}
}
f = sqrt(fx*fx + fy*fy);
dirf = atan(fy/fx);
angdirf = (dirf/(22.0/7.0))*180;
System.out.printf("The force on m["+ mi +"] due to the other masses is %eN, %fdeg\n",f,angdirf);
}
}
}
Source code GravityAttract07a.java
/* Java class for calculating the resultant force on any object
(i.e either on m1,m2,m3,m4,or m5)
*/

import static java.lang.Math.*;

public class GravityAttract07a


{
public static void main(String args[])
{
double[] m = new double[6]; // mass of object
double[] x = new double[6]; // x-coor of object
double[] y = new double[6]; // y-coor of object
double f; // resultant force
double fx,fy; // x & y component of force
double rx, ry, rp, co, G, dirf,angdirf;
int j, mi;

G = 6.67e-11;
m[1]=2.5; x[1]=1.2; y[1]=2.5;
m[2]=1.5; x[2]=1.5; y[2]=1.5;
m[3]=7.5; x[3]=0.2; y[3]=5.5;
m[4]=9.2; x[4]=5.2; y[4]=2.5;
m[5]=6.6; x[5]=4.2; y[5]=4.5;
System.out.print("On which mass you want to calculate the resulting force ? " );
mi = TextIO.getlnInt();
fx = 0.0;
fy = 0.0;
for(j=1; j<=5; j++)
{
if (j!=mi)
{
rx = x[j]-x[mi];
ry = y[j]-y[mi];
rp = pow((rx*rx+ry*ry),1.5); // (rx^2 + ry^2) raised to the power of 3/2
co = G*m[mi]*m[j];
fx = fx + co*rx/rp;
fy = fy + co*ry/rp;
}
}
f = sqrt(fx*fx + fy*fy);
dirf = atan(fy/fx);
angdirf = (dirf/(22.0/7.0))*180;
System.out.printf("The force on m["+ mi +"] due to the other masses is %eN, %fdeg\n",f,angdirf);
}
}

S-ar putea să vă placă și