I am Paul G. I am a Mechanical Engineering Assignment Expert at matlabassignmentexperts.com. I hold a Ph.D. Matlab, University of Adelaide, Australia. I have been helping students with their homework for the past 10 years. I solve assignments related to Mechanical Engineering.
Visit matlabassignmentexperts.com or email info@matlabassignmentexperts.com.
You can also call on +1 678 648 4277 for any assistance with Mechanical Engineering Assignments.
1. Mechanical engineering assignment help
For any help regarding Matlab Assignment Help
visit : https://www.matlabassignmentexperts.com/ ,
Email info@matlabassignmentexperts.com or
call us at - +1 678 648 4277
matlabassignmentexperts.com
2. Problem 1 : Dynamics of a mass-spring-damper system
F t F0 sin t
k x
m
b x0 &v0
A mass-spring-damper system is subject to an external sinusoidal force F t with amplitude
F0 , and angular frequency . The position of particle, x , is zero when the spring is neither
compressed or stretched. The mass of the particle is m , the damping coefficient is b and the spring constant is k . Initial
condition is expressed as x(0) x0 and v(0) v0 . Derive the equation of motion for this mass-spring-damper system.
Problem 2 : Solver for a mass-spring-damper system using Euler method
You are familiar with Euler method used to obtain the trajectory of a ball dropping and bouncing in Homework #3. In this
homework, you will create a function that use Euler method to derive the particle trajectory (two column matrix for time
and position each) in mass-spring-damper
system from t=0 to 50 sec. The input parameters of the function are coefficients ( m , b , k , F0
and ) and initial conditions ( x0 and v0 ). Use time increment t 0.1sec . Function name (and m-file name) should be
‘MSDSE_your_kerberos_name’ and upload it to 2.003 MIT Server site. You also submit the hardcopy of your
code with appropriate comments.
Problems
matlabassignmentexperts.com
3. Problem 3 :
Solver for a mass-spring-damper system with using Runge-Kutta method
Using Runge-Kutta algorithm to solve the differential equation of this system, generate a m-file function with input parameters (
m , b , k , F0 , , x0 and v0 ) to calculate particle
trajectory (two column matrix for time and position each) from t=0 to 50 sec. You may use either Runge-Kutta 23 or 45 algorithm (See
ode23 or ode45 in the MATLAB help, and use one of them in your m-code.). Use t 0.1sec for both the time step size for the
solver (See also odeset
in the MATLAB help) and the time step for the output time from the solver (See input argument for
tspan in ode23 or ode45). Function name (and m-file name) should be
‘MSDSRK_your_kerberos_name’ and upload it to 2.003 MIT Server site. You also submit the hardcopy of your code with
appropriate comments.
Problem 4 : Trajectory of a mass-spring-damper system with different parameters and initial conditions
For the following cases, plot the time response of the particle. Plot the trajectories with Euler and Runge-Kutta solvers on a single
graph with appropriate legends. Compare the results for these two approaches. Submit a hardcopy of your trajectory plots.
i) m 1kg , b 0.5 Nsec/m , k 1 N/m , F0 1N , 3 rad/sec , x(0) 0m and
v(0) 0m/ sec
ii) m 1kg , b 0.5 Nsec/m , k 1 N/m , F0 0N , 0 rad/sec , x(0) 1m and
v(0) 0m/ sec
iii) m 1kg , b 0 Nsec/m , k 1 N/m , F0 1N , 1 rad/sec , x(0) 0m and
v(0) 0m / sec
matlabassignmentexperts.com
4. Solutions
Problem 1 : Dynamics of mass-spring-damper system
From the above diagram,
Problem 2 : Solver for mass-spring-damper system with Euler method
First, 2nd order differential equation is split into two 1st order differential equations as did in
Homework #3.
matlabassignmentexperts.com
5. With Eq.(3), we also obtain the discrete version of above differential equations.
xn,1 x1 nt & xn,2 x2 nt
xn 1,1 xn,1 xn,2t xn 1,
2 xn,2 at
where
0
a
1
F sinnt b xn,2 k xn,1
m
The solver of mass-spring-damper system with Euler method is implemented as below. Explanation of each command line is
included in the following codes.
function O=MSDSE(m,b,k,F0,w,x0,v0)
%
% Solver for Mass-Sprring-Damper System with Euler Method
% ----- Input argument -----
% m: mass for particle
% b: damping coefficient
% k: spring constant
% F0: amplitude of external force
% w: angular freuency of external force
% x0: initial condition for the position x(0)
% v0: initial condition for the velocity v(0)
% ----- Output argument -----
% t: time series with given time step from ti to tf.
% x: state variable matrix for corresponding time t matrix
% Define time step in Euler method dt=0.1;
% Make time series with given time step t=[0:dt:50]';
% Initialize output matrix
% the 1st column: the position of the particle
% the 2nd column: the veleocity of the particle x=zeros(length(t),2);
% the 1st row has initial conditions x(1,:)=[x0 v0];
% Start the simulation with Euler method for i=1:length(t)-1
matlabassignmentexperts.com
6. % Apply Euler method
% x(n+1)=x(n)*v(n)*dt x(i+1,1,1)=x(i,1)+x(i,2)*dt;
% v(n+1)=v(n)*a(n)*dt
%where a(n)=1/m*(F0sin(wt)-bv(n)-kx(n))*dt x(i+1,2)=x(i,2)+(1/m)*(F0*sin(w*t(i))-b*x(i,2)-
k*x(i,1))*dt;
end
% Extract only particle position trajectory O=[t,x(:,1)];
end
Problem 3 : Solver for mass-spring-damper system with Runge-Kutta method
Unlike Euler method, you don’t need to solve differential equation itself in MATLAB. (You can also make your own code for Runge-Kutta algorithm
for yourself.) However, the subfunction should
be needed to implement Runge-Kutta algorithm. (Single m-file can have several functions. The
first one is the primary function, and others are subfunction.) Subfunction includes several 1st
order differential equations by splitting higher order
differential equation. In our case, two 1st
order equations are used as described in problem 6.2. With this subfunction, the solver (either
‘ode23’ or ‘ode45’) solves differential equations actually. The handler of function which has dynamic equation description, time span which
the solver calculates between, and initial condition at the simulation starting time are at least specified as the input arguments when the solver
runs. More detailed syntax description of either ‘ode23’ or ‘ode45’ is shown in MATLAB help. The solver of mass-spring-damper system
with Runge-Kutta method is implemented as below. Explanation of each command line is included in the following codes.
function O=MSDSRK(m,b,k,F0,w,x0,v0)
%
% Solver for Mass-Sprring-Damper System with Runge-Kutta Method
% ----- Input argument -----
% m: mass for particle
% b: damping coefficient
% k: spring constant
% F0: amplitude of external force
% w: angular freuency of external force
matlabassignmentexperts.com
7. % x0: initial condition for the position x(0)
% v0: initial condition for the velocity v(0)
% ----- Output argument -----
% t: time series with given time step from ti to tf.
% x: state variable matrix for corresponding time t matrix
% define time steps for solver and display dt=0.1;
% set both initial time step size and maximum step size
% for Runge-Kutta solver options=odeset('InitialStep',dt,'MaxStep',dt);
% set time span to be generated from Runge-Kutta solver
% from 0 sec to 50 sec with 0.1 sec time step td=[0:dt:50];
% Solve differential equation with Runge-Kutta solver
[t,x]=ode45(@(t,X)MSD(t,X,m,b,k,F0,w),td,[x0;v0],options);
% Extract only particle position trajectory O=[t x(:,1)];
end
function dX=MSD(t,X,m,b,k,F0,w)
%
% With two 1st order diffeential equations,
% obtain the derivative of each variables
% (position and velocity of the particle)
%
% t: current time
% X: matrix for state variables
% The first column : the particle position
% The second column : the particle velocity
% m,b,k,F0,w: parameters for the system
%
% Apply two 1st order differential equations
% dx(n+1)/dt<-v(n)
matlabassignmentexperts.com
8. dX(1,1)=X(2,1);
% dv(n+1)/dt<-1/m*(F0sin(wt)-bv(n)-kx(n))
dX(2,1)=(1/m)*(F0*sin(w*t)-b*X(2,1)-k*X(1,1)); end
Problem 4 : Trajectory of mss-spring-damper system with different parameters and initial conditions
i) Following code is used to generate below plot.
>> Oe=MSDSE(1,0.5,1,1,3,0,0);
>> Or=MSDSRK(1,0.5,1,1,3,0,0);
>> plot(Oe(:,1),Oe(:,2),'r',Or(:,1),Or(:,2),'b--','LineWidth',2); axis tight; grid on;
>> xlabel('bfTime (sec)'); ylabel('bfParticle Position (m)');
>> title({'bf Mass-Spring-Damper System Simulation'; 'm=1kg, b=0.5Nsec/m, k=1N/m, F_0=1m,
omega=3rad/sec, x_0=0m, & v_0=0m/sec'})
>> legend('bfEuler','bfRunge-Kutta','Location','NorthEast')
It’s the response of the sinusoidal excitation for the particle when it is stationary, and no spring is compressed or stretched. Comparing two
results from Euler method and Runge- Kutta method, they produce similar simulation results. The plot is shown as below:
matlabassignmentexperts.com
9. ii) Following code is use to generate below plot.
>> Oe=MSDSE(1,0.5,1,0,0,1,0);
>> Or=MSDSRK(1,0.5,1,0,0,1,0);
>> plot(Oe(:,1),Oe(:,2),'r',Or(:,1),Or(:,2),'b--','LineWidth',2); axis tight; grid on;
>> xlabel('bfTime (sec)'); ylabel('bfParticle Position (m)');
>> title({'bf Mass-Spring-Damper System Simulation'; 'm=1kg, b=0.5Nsec/m, k=1N/m, F_0=0m,
omega=0rad/sec, x_0=1m, & v_0=0m/sec'})
>> legend('bfEuler','bfRunge-Kutta','Location','NorthEast')
iii) Following code is use to generate below plot.
It’s the response with no external force and no damping when the spring is initially stretched. Comparing two results from Euler method and
Runge-Kutta method, Runge- Kutta method is more accurate than Euler method, based on the analytical solution of this system. The plot is
shown as below:1
>> Oe=MSDSE(1,0,1,1,1,0,0);
>> Or=MSDSRK(1,0,1,1,1,0,0);
>> plot(Oe(:,1),Oe(:,2),'r',Or(:,1),Or(:,2),'b--','LineWidth',2); axis tight; grid on;
matlabassignmentexperts.com
10. >> xlabel('bfTime (sec)'); ylabel('bfParticle Position (m)');
>> title({'bf Mass-Spring-Damper System Simulation'; 'm=1kg, b=0Nsec/m, k=1N/m, F_0=1m,
omega=1rad/sec, x_0=0m, & v_0=0m/sec'})
>> legend('bfEuler','bfRunge-Kutta','Location','NorthWest')
It’s the response of external force with the system resonance frequency when the spring is initially stretched. Resonance happens very quickly,
which means the particle position oscillates from to . However, numerical simulation has limitation to express the infinity. Therefore,
as time goes on, oscillations for both methods become larger, but Euler method one has smaller oscillation, compared with Runge-Kutta one.
So, Euler method is not powerful near the singularity. The plot is shown as below:
Mass-Spring-Damper System Simulation
m=1kg, b=0Nsec/m, k=1N/m, F0=1m, =1rad/sec, x0=0m, & v0=0m/sec
60
40
20
0
-20
-40
-60
-80
80
Particle
Position
(m)
Euler
Runge-Kutta
0 5 10 15 20 30 35 40 45 50
25
Time (sec)
matlabassignmentexperts.com
11. function O=MSDSE(m,b,k,F0,w,x0,v0)
%
% Solver for Mass-Sprring-Damper System with Euler Method
% ----- Input argument -----
% m: mass for particle
% b: damping coefficient
% k: spring constant
% F0: amplitude of external force
% w: angular freuency of external force
% x0: initial condition for the position x(0)
% v0: initial condition for the velocity v(0)
% ----- Output argument -----
% t: time series with given time step from ti to tf.
% x: state variable matrix for corresponding time t matrix
% Define time step in Euler method
dt=0.1;
% Make time series with given time step
t=[0:dt:50]';
% Initialize output matrix
% the 1st column: the position of the particle
% the 2nd column: the veleocity of the particle
x=zeros(length(t),2);
% the 1st row has initial conditions
x(1,:)=[x0 v0];
% Start the simulation with Euler method
matlabassignmentexperts.com
12. for i=1:length(t)-1
% Apply Euler method
% x(n+1)=x(n)*v(n)*dt
x(i+1,1,1)=x(i,1)+x(i,2)*dt;
% v(n+1)=v(n)*a(n)*dt
%where a(n)=1/m*(F0sin(wt)-bv(n)-kx(n))*dt
x(i+1,2)=x(i,2)+(1/m)*(F0*sin(w*t(i))-b*x(i,2)-k*x(i,1))*dt;
end
% Extract only particle position trajectory
O=[t,x(:,1)];
end
function O=MSDSRK(m,b,k,F0,w,x0,v0)
%
% Solver for Mass-Sprring-Damper System with Runge-Kutta Method
% ----- Input argument -----
% m: mass for particle
% b: damping coefficient
% k: spring constant
% F0: amplitude of external force
% w: angular freuency of external force
% x0: initial condition for the position x(0)
% v0: initial condition for the velocity v(0)
% ----- Output argument -----
% t: time series with given time step from ti to tf.
% x: state variable matrix for corresponding time t matrix
matlabassignmentexperts.com
13. % define time steps for solver and display
dt=0.1;
% set both initial time step size and maximum step size
% for Runge-Kutta solver
options=odeset('InitialStep',dt,'MaxStep',dt);
% set time span to be generated from Runge-Kutta solver
% from 0 sec to 50 sec with 0.1 sec time step
td=[0:dt:50];
% Solve differential equation with Runge-Kutta solver
[t,x]=ode45(@(t,X)MSD(t,X,m,b,k,F0,w),td,[x0;v0],options);
% Extract only particle position trajectory
O=[t x(:,1)];
end
function dX=MSD(t,X,m,b,k,F0,w)
%
% With two 1st order diffeential equations,
% obtain the derivative of each variables
% (position and velocity of the particle)
%
% t: current time
% X: matrix for state variables
% The first column : the particle position
% The second column : the particle velocity
% m,b,k,F0,w: parameters for the system
%
matlabassignmentexperts.com
14. % Apply two 1st order differential equations
% dx(n+1)/dt<-v(n)
dX(1,1)=X(2,1);
% dv(n+1)/dt<-1/m*(F0sin(wt)-bv(n)-kx(n))
dX(2,1)=(1/m)*(F0*sin(w*t)-b*X(2,1)-k*X(1,1));
end
matlabassignmentexperts.com