MatLab Spring Damping and Energy

Click For Summary
SUMMARY

The discussion focuses on analyzing a mass-spring system with damping using MATLAB. The differential equation governing the system is my′′ + gammay′ + ky = 0, with parameters m = 1, k = 4, and gamma = 1. Participants provide MATLAB code for plotting solutions of position and velocity over time, as well as phase plots and energy calculations. Key tasks include plotting the energy E = 1/2mv^2 + 1/2ky^2 as a function of time and demonstrating the behavior of energy over time based on the damping coefficient gamma.

PREREQUISITES
  • Understanding of differential equations, specifically second-order linear DEs.
  • Familiarity with MATLAB, particularly the ode45 function for solving DEs.
  • Knowledge of energy concepts in mechanical systems, including kinetic and potential energy.
  • Ability to create plots in MATLAB for data visualization.
NEXT STEPS
  • Learn how to implement energy calculations in MATLAB for dynamic systems.
  • Explore MATLAB's contour plotting capabilities for visualizing energy states.
  • Study the impact of varying damping coefficients on system behavior in mass-spring systems.
  • Investigate the analytical methods for deriving energy conservation principles in damped systems.
USEFUL FOR

Students and professionals in mechanical engineering, physics, and applied mathematics, particularly those working with dynamic systems and MATLAB simulations.

vaqueradecali
Messages
1
Reaction score
0
This is the entire problem. I am looking for help with part 3.

For the mass-spring system with damping, we obtain the following DE
my′′ + gammay′ + ky = 0, or y′′ + cy′ + omega^2y = 0, where c = gamma/m and omega^2 = k/m. Given m = 1,k = 4, gamma= 1, and initial conditions y(0) = 0.1, y′(0) = 0.
(1) Plot solutions y and v = y′ = dy/dt as functions of time.
(2) Plot v vs y (phase plot). Comment on the behavior of the curve.
(3) Plot the quantity E = 1/2mv^2 + 1/2ky^2 as a function of time. What do you observe?
(4) Show that dE/dt < 0 for gamma > 0 while dE/dt > 0 for gamma < 0 (analytically or by graphic).


For part 1
function Q2part1
m = 1; % mass [kg]
k = 4; % spring constant [N/m]
gamma = 1; % friction coefficient [Ns/m]
omega = sqrt(k/m); c = gamma/m;
y0 = 0.1; v0 = 0; % initial conditions
[t,Y] = ode45(@f,[0,10],[y0,v0],[],omega,c); % solve for 0<t<10
y = Y(:,1); v = Y(:,2); % retrieve y, v from Y
figure(1); plot(t,y,'b+-',t,v,'ro-'); % time series for y and v
%-------------------------------------------
function dYdt = f(t,Y,omega,c)
y = Y(1); v = Y(2);
dYdt = [ v ;-c*(v)-omega^2*y];

for part 2

function Q2part2
m = 1;
k = 4;
gamma = 1;
omega = sqrt(k/m); c = gamma/m;
y0 = 0.1; v0 = 0;
[t,Y] = ode45(@f,[0,10],[y0,v0],[],omega,c);
y = Y(:,1); v = Y(:,2);
figure(1); plot(v,y);
function dYdt = f(t,Y,omega,c)
y = Y(1); v = Y(2);
dYdt = [ v ;-c*(v)-omega^2*y];


I know that i need to plug in formulas for y (and v as well?) so that I have E(t), but is it as simple as solving for and plugging in y? I am in need of direction here I suppose...a nice big fat hint to put me in the correct direction.:biggrin:
 
Physics news on Phys.org
I don't know which part you need help with, but if you are on part three you should look into a contour plot.

For example, here is a way to do an energy contour of a undamped oscillator with a mass of 4.5kg and a spring constant of 2N/m:

[x y]=meshgrid(-1:0.01:1,-1:0.01:1);

m=4.5;
k=2;

contour(x,y,((1/2)*m*y.^2)+((1/2)*k*x.^2),4)
title('Energy Contour Plot for Undamped Oscillations')
ylabel('Velocity')
xlabel('Position')
 
Oh whoops, they asked for it as a function of time... which I don't quite understand. Maybe you could overlay the potential energy vs. time and the kinetic energy vs. time onto one plot.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 18 ·
Replies
18
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
1
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K