0% found this document useful (0 votes)
207 views

Matlab HW PDF

The document contains 3 MATLAB problems: 1) Plot the response of a damped harmonic oscillator over time. 2) Write a function to calculate the equivalent stiffness of two springs in series. 3) Generate a 3D surface plot of the total energy of a spring-mass system.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
207 views

Matlab HW PDF

The document contains 3 MATLAB problems: 1) Plot the response of a damped harmonic oscillator over time. 2) Write a function to calculate the equivalent stiffness of two springs in series. 3) Generate a 3D surface plot of the total energy of a spring-mass system.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

ME 4600: 431 MATLAB

Homework 01
Use MATLAB for the following problems:
Problem 1:
The response of a damped harmonic oscillator can be expressed as:
x(t) = e
n t

x
0
+
n
x
0

1
2

sin

1
2
t

+ x
0
cos

1
2
t

,
provided || < 1. In this expression x
0
and x
0
represent the initial displacement and
velocity respectively, while is the damping ratio and
n
is known as the natural frequency.
Using MATLAB, plot the response x(t) over the interval 0 t 10 for:
x
0
= 1.00, x
0
= 0.25,
with = 0.50 and
n
= 4.00.
Solution:
In MATLAB, we rst dene the independent variable t, then calculate the dependent
variable y(t), and nally generate the plot. This can be accomplished with the following
commands:
% define the array t from t=0 to t=10 with increments of 0.1
t = 0:0.1:10;
% define the parameters and initial conditions
zeta = 0.50;
omegan = 4.00;
x0 = 1.00;
xdot0 = -0.25;
% for simplicity we identify the following groups:
% tau = zeta*omegan, omegad = omegan*sqrt(1-zeta^2),
% A = (xdot0 + tau*x0)/omegad, B = x0,
tau = zeta*omegan;
omegad = omegan*sqrt(1-zeta^2);
A = (xdot0 + tau*x0)/omegad;
B = x0;
% calculate the dependent function
x = exp(-tau*t).*( A*sin(omegad*t) + B*cos(omegad*t) );
% finally, generate the plot
plot(t,x);
xlabel(t); ylabel(x(t));
title(Response of an Underdamped Linear Oscillator)
These can all be combined into a single MATLAB function.
Problem 2:
Write a MATLAB function to calculate the equivalent stiness of two springs in series.
The function should take, as its two arguments, the two individual spring constants and
return the equivalent stiness.
Solution:
For n springs in series, the equivalent spring constant is:
1
k
eq
=
n

i=1
1
k
i
.
A suitable MATLAB function could be dened as:
function [keq] = springseries(k1,k2)
% function springseries
% input: k1, k2 (individual spring constants)
% output: keq (equivalent spring constant)
keq = 1/(1/k1 + 1/k2);
Using this function in MATLAB:
springseries(1.00, 3.00)
ans = 0.7500
For multiple springs in series a suitable MATLAB function could be dened
as:
function [keq] = springseries(kn)
% function springseries
% input: kn (array of n spring constants)
% e.g., kn=[1 1 4 5];
% output: keq (equivalent spring constant)
keq = 1/sum(1./k);
Problem 3:
Generate a three-dimensional surface plot of the total energy for a spring-mass system of
the form:
m x + 2 k x = mg,
with m = 4 kg, k = 100 N/m, and g = 9.81 m/s
2
.
Solution:
For this system the kinetic and potential energies can be written as:
T =
1
2
m x
2
, V =
1
2
(2 k) x
2
mg x,
so that the total energy becomes:
E = T + V =
m
2
x
2
+ k x
2
mg x.
The following MATLAB commands will produce this surface:
% define the variables x and xdot
x = -0.50:0.05:1.00;
xdot = -4.00:0.40:4.00;
% define the system parameters
m = 4.00;
k = 100;
g = 9.81;
% use meshgrid to define a grid for the independent variables
% x and xdot
[xm,ym] = meshgrid(x,xdot);
% calculate the total energy over this grid
E = (m/2)*ym.^2 + k*xm.^2 - m*g*xm;
% finally, generate the plot with surf
surf(x,xdot,E);
xlabel(x); ylabel(xdot); zlabel(E);
title(Total Energy);
% the command surfc also produces a surface plot,
% but includes a contour plot of the surface below
surf(x,xdot,E);
xlabel(x); ylabel(xdot); zlabel(E);
title(Total Energy);

You might also like