- #1
200917717
- 8
- 0
https://www.physicsforums.com/attachments/251691. Homework Statement
assigned system of masses connected by springs with the parameters specified
Mass M0 details:
Stationary mass, does not move
Starting Positions in meters:
X: 5.8
Y: 4.2
-----------------------------------------
Mass M1 details:
Mass 14 kg
Starting Positions in meters:
X: 5.8
Y: 3
-----------------------------------------
Mass M2 details:
Mass 16 kg
Starting Positions in meters:
X: 5.4
Y: 5.6
-----------------------------------------
Mass M3 details:
Mass 14 kg
Starting Positions in meters:
X: 4.2
Y: 4.8
-----------------------------------------
#####################################################################
Spring S0 details:
K: 0.78
Equilibrium Distance (meters):
Eq: 0.9
-----------------------------------------
Spring S1 details:
K: 0.7
Equilibrium Distance (meters):
Eq: 1.6
-----------------------------------------
Spring S2 details:
K: 1.02
Equilibrium Distance (meters):
Eq: 1.3
-----------------------------------------
Spring S3 details:
K: 0.78
Equilibrium Distance (meters):
Eq: 1
-----------------------------------------
Spring S4 details:
K: 0.66
Equilibrium Distance (meters):
Eq: 0.8
Using model it must simulate the movement of all the masses from 0 to 100 seconds (including 100) with a time step of 0.1 seconds. Record the position of each mass (X and Y position) at every time step in an array. You will then plot the path of each mass in a different colour on a single plot with the X Axis to run from 0 to 10 meters and the Y axis from 0 to 7.5 meters.No friction or gravity
F=-kx where k is the spring constant and x is the displacement from the springs equilibrium point.
Fx=Fcos(θ) where Theta is the angle at which the spring is pulling.
Fy=Fsin(θ)
You add up all the X component forces and Y component forces for a specific mass to find the result X and Y component force acting on that mass. Once you have the resultant force acting on a specific mass you can find its Acceleration from the following:
Fres = ma thus a = m/Fres
a=∆v/∆t thus ∆V=a∆t
∆V= ∆s/∆t thus ∆s= ∆v∆t
code for start
clear all;
close all;
clc;
%position of peg
pegX = 5.8;
pegY = 4,2;
%position of mass
xPos1 = 5.8;
yPos1 = 3;
xPos2 = 5.4;
yPos2 = 5.6;
xPos3 =4.2 ;
yPos3 = 4.8;
%velocity of mass
xVel1 = 0;
yVel1 = 2;
xVel2 = 1.67;
yVel2 = 2.79;
xVel3 = -0.64;
yVel3 = -3.19;
xVel4 = -6;
yVel4 = 5;
%mass of mass
m1 = 14;
m2 = 16;
m3 = 14;
%constant of spring
kpeg = 0.78;
k1 = 0.7;
k2 = 1.02;
k3 = 0.78;
%equilibrium distance of spring
egpeg = 0.9;
eq1 = 1.6;
eq2 = 1.3
eq3 = 1;
%constant of gravity
g = 0.5;
%define time domain
dt = 0.1;
t = 0:dt:100;
%record all previos positions for plot
positions = zeros(4,length(t));
for i = 1:length(t)
%find angle between peg and mass
theta1 = direction(xPos1,yPos1,pegX,pegY);
theta2 = direction(xPos3,yPos3,xPos1,yPos1);
theta3 = direction(xPos2,yPos2,xPos3,yPos3);
theta4 = direction(xPos1,yPos1,xPos2,yPos2);
theta5 = direction(pegX,pegY,xPos2,yPos2);
%calc X resultant force
FresX1 = -1*(eq1-dist(xPos1,yPos1,pegX,pegY))*k1*cos(theta1);
FresX2 = -1*(eq2-dist(xPos2,yPos2,xPos1,yPos1))*k2*cos(theta2);
FresX3 = -1*(eq3-dist(xPos3,yPos3,xPos2,yPos2))*k2*cos(theta3);
%calc Y resultant force
FresY1 = -1*(eq1-dist(xPos1,yPos1,pegX,pegY))*k1*sin(theta1) - m1*g;`clear all;
FresY3 = -1*(eq3-dist(xPos3,yPos3,xPos1,yPos1))*k3*sin(theta2) - m3*g;`clear all;
FresY2 = -1*(eq2-dist(xPos2,yPos,xPos3,yPos3))*k2*sin(theta3) - m2*g;`clear all;
FresY4 = -1*(eq1-dist(xPos1,yPos1,xPos2,yPos2))*k1*sin(theta4) - m1*g;`clear all;
FresY5 = -1*(eqpeg-dist(xPospegx,yPospegy,xPos2,yPos2))*kpeg*sin(theta5) - mpeg*g;`clear all;
%calculate acceleration due to force
aX1 = FresX1/m1;
aY1 = FresY1/m1;
aX2 = FresX2/m2;
aY2 = FresY2/m2;
aX3 = FresX3/m3;
aY3 = FresY3/m2;
%change velocity based on acceleration
xVel1 = xVel1 + aX1*dt;
yVel1 = yVel1 + aY1*dt;
xVel2 = xVel2 + aX2*dt;
yVel2 = yVel2 + aY2*dt;
xVel3 = xVel3 + aX3*dt;
yVel3 = yVel3 + aY3*dt
%change position based on velocity
xPos1 = xPos1 + xVel1*dt;
yPos1 = yPos1 + yVel1*dt;
xPos2 = xPos2 + xVel2*dt;
yPos2 = yPos2 + yVel2*dt;
xPos3 = xPos3 + xVel3*dt;
yPos2 = yPos3 + yVel3*dt;
%record position for plot
positions(1,i) = xPos1;
positions(2,i) = yPos1;
positions(3,i) = xPos2;
positions(4,i) = yPos2;
positions(5,i) = xPos3;
positions(6,i) = yPos3;
end
%plot position
p1 = plot(positions(1,:),positions(2,:),'r');
p2 = plot(positions(3,:),positions(4,:),'b');
p2 = plot(positions(5,:),positions(6,:),'g');
grid on;
Code for direction:
function [ a ] = direction(x1,y1,x2,y2 )
%DIRECTION find direction of line between the 2 points
a = atan2(y2-y1,x2-x1);
end
code for distance:
function [ d] = dist( x1,y1,x2,y2)
%DIST calculate euclidian distance between 2 points
d = sqrt((x1-x2)^2+(y1-y2)^2);
end
assigned system of masses connected by springs with the parameters specified
Mass M0 details:
Stationary mass, does not move
Starting Positions in meters:
X: 5.8
Y: 4.2
-----------------------------------------
Mass M1 details:
Mass 14 kg
Starting Positions in meters:
X: 5.8
Y: 3
-----------------------------------------
Mass M2 details:
Mass 16 kg
Starting Positions in meters:
X: 5.4
Y: 5.6
-----------------------------------------
Mass M3 details:
Mass 14 kg
Starting Positions in meters:
X: 4.2
Y: 4.8
-----------------------------------------
#####################################################################
Spring S0 details:
K: 0.78
Equilibrium Distance (meters):
Eq: 0.9
-----------------------------------------
Spring S1 details:
K: 0.7
Equilibrium Distance (meters):
Eq: 1.6
-----------------------------------------
Spring S2 details:
K: 1.02
Equilibrium Distance (meters):
Eq: 1.3
-----------------------------------------
Spring S3 details:
K: 0.78
Equilibrium Distance (meters):
Eq: 1
-----------------------------------------
Spring S4 details:
K: 0.66
Equilibrium Distance (meters):
Eq: 0.8
Using model it must simulate the movement of all the masses from 0 to 100 seconds (including 100) with a time step of 0.1 seconds. Record the position of each mass (X and Y position) at every time step in an array. You will then plot the path of each mass in a different colour on a single plot with the X Axis to run from 0 to 10 meters and the Y axis from 0 to 7.5 meters.No friction or gravity
Homework Equations
F=-kx where k is the spring constant and x is the displacement from the springs equilibrium point.
Fx=Fcos(θ) where Theta is the angle at which the spring is pulling.
Fy=Fsin(θ)
You add up all the X component forces and Y component forces for a specific mass to find the result X and Y component force acting on that mass. Once you have the resultant force acting on a specific mass you can find its Acceleration from the following:
Fres = ma thus a = m/Fres
a=∆v/∆t thus ∆V=a∆t
∆V= ∆s/∆t thus ∆s= ∆v∆t
The Attempt at a Solution
code for start
clear all;
close all;
clc;
%position of peg
pegX = 5.8;
pegY = 4,2;
%position of mass
xPos1 = 5.8;
yPos1 = 3;
xPos2 = 5.4;
yPos2 = 5.6;
xPos3 =4.2 ;
yPos3 = 4.8;
%velocity of mass
xVel1 = 0;
yVel1 = 2;
xVel2 = 1.67;
yVel2 = 2.79;
xVel3 = -0.64;
yVel3 = -3.19;
xVel4 = -6;
yVel4 = 5;
%mass of mass
m1 = 14;
m2 = 16;
m3 = 14;
%constant of spring
kpeg = 0.78;
k1 = 0.7;
k2 = 1.02;
k3 = 0.78;
%equilibrium distance of spring
egpeg = 0.9;
eq1 = 1.6;
eq2 = 1.3
eq3 = 1;
%constant of gravity
g = 0.5;
%define time domain
dt = 0.1;
t = 0:dt:100;
%record all previos positions for plot
positions = zeros(4,length(t));
for i = 1:length(t)
%find angle between peg and mass
theta1 = direction(xPos1,yPos1,pegX,pegY);
theta2 = direction(xPos3,yPos3,xPos1,yPos1);
theta3 = direction(xPos2,yPos2,xPos3,yPos3);
theta4 = direction(xPos1,yPos1,xPos2,yPos2);
theta5 = direction(pegX,pegY,xPos2,yPos2);
%calc X resultant force
FresX1 = -1*(eq1-dist(xPos1,yPos1,pegX,pegY))*k1*cos(theta1);
FresX2 = -1*(eq2-dist(xPos2,yPos2,xPos1,yPos1))*k2*cos(theta2);
FresX3 = -1*(eq3-dist(xPos3,yPos3,xPos2,yPos2))*k2*cos(theta3);
%calc Y resultant force
FresY1 = -1*(eq1-dist(xPos1,yPos1,pegX,pegY))*k1*sin(theta1) - m1*g;`clear all;
FresY3 = -1*(eq3-dist(xPos3,yPos3,xPos1,yPos1))*k3*sin(theta2) - m3*g;`clear all;
FresY2 = -1*(eq2-dist(xPos2,yPos,xPos3,yPos3))*k2*sin(theta3) - m2*g;`clear all;
FresY4 = -1*(eq1-dist(xPos1,yPos1,xPos2,yPos2))*k1*sin(theta4) - m1*g;`clear all;
FresY5 = -1*(eqpeg-dist(xPospegx,yPospegy,xPos2,yPos2))*kpeg*sin(theta5) - mpeg*g;`clear all;
%calculate acceleration due to force
aX1 = FresX1/m1;
aY1 = FresY1/m1;
aX2 = FresX2/m2;
aY2 = FresY2/m2;
aX3 = FresX3/m3;
aY3 = FresY3/m2;
%change velocity based on acceleration
xVel1 = xVel1 + aX1*dt;
yVel1 = yVel1 + aY1*dt;
xVel2 = xVel2 + aX2*dt;
yVel2 = yVel2 + aY2*dt;
xVel3 = xVel3 + aX3*dt;
yVel3 = yVel3 + aY3*dt
%change position based on velocity
xPos1 = xPos1 + xVel1*dt;
yPos1 = yPos1 + yVel1*dt;
xPos2 = xPos2 + xVel2*dt;
yPos2 = yPos2 + yVel2*dt;
xPos3 = xPos3 + xVel3*dt;
yPos2 = yPos3 + yVel3*dt;
%record position for plot
positions(1,i) = xPos1;
positions(2,i) = yPos1;
positions(3,i) = xPos2;
positions(4,i) = yPos2;
positions(5,i) = xPos3;
positions(6,i) = yPos3;
end
%plot position
p1 = plot(positions(1,:),positions(2,:),'r');
p2 = plot(positions(3,:),positions(4,:),'b');
p2 = plot(positions(5,:),positions(6,:),'g');
grid on;
Code for direction:
function [ a ] = direction(x1,y1,x2,y2 )
%DIRECTION find direction of line between the 2 points
a = atan2(y2-y1,x2-x1);
end
code for distance:
function [ d] = dist( x1,y1,x2,y2)
%DIST calculate euclidian distance between 2 points
d = sqrt((x1-x2)^2+(y1-y2)^2);
end
Attachments
Last edited: