You are on page 1of 6

MatlabHWAssignment3(Due:October1,2008)

PH375Fall2008

Instructions:CompletethefollowingassignedtasksusingMatlab.Stapleyourworktogetherinthe
followingorder.ThewrittensolutionstoanygivenproblemsshouldbefirstfollowedbyyourMatlab
codeandMatlabfigures.Thewrittensolutionsshouldbecomplete,neat,andinorderifthereare
multipleproblems.TheMatlabcodeneedstobeneat,documented,andMUSTexecuteonmymachine.
AllMatlabfiguresturnedinmustbewellpresentedwhichincludesaxeslabels,title,units,alegend(if
appropriate),goodaxesscaling,curvefitwithequationoffit(ifrequested),andanytextboxesonthe
figurewhichmayhelpexplaintheplot(thisisrarebutsomethingtoconsider).

Exercise1:Consideraspringmassoscillatorofmass10.0kgonahorizontaltabletop.Thespringhasa
stiffnessconstantof250.0N/m.Thesurfacebetweenthemassandthetabletophasavelocity
dependentdragforceoftheform b whereb=3.0kg/s. x

2
(u) = 1 (

(A) Derivetheequationofmotionforthissystemanddefinethedampingparameterandnatural
frequencyofthesystem.
(B) UsingMatlab,plotthedisplacementasafunctionoftimefortheoscillatorouttot=20.0susing
thesolutiontothedifferentialequation.Overlayonthesameplotasetoftwolines(oneabove
andonebelowthex=0line)whichrepresentthelimittotheamplitudeofoscillationasa
functionoftime.
(C) UsingMatlab,generatethesameplotofdisplacementasafunctionoftimeforthisoscillator
exceptthistimeusetheODE45solver.UsethesametimerangeasinpartB.

Exercise2:Nowwewillchangeupthesystem.Systemswithquadraticvelocitydependentdamping
forcesaremorecommoninrealitysoletusassumethatwehaveanoscillatorthatexperiencessucha
force.Themagnitudeofthedampingforcecanbewrittenascx .Thespringasamassof1.0kganda
stiffnessconstantofk=4.0N/m.Thedampingconstantc=0.40kg/m/s.

(A) Determinetheequationofmotionforthisdampedoscillator.Definecoefficientsinfrontofthe
x
2
andxcomponentsappropriately.[Hint:Inorderforthedampingterm, x
2
,tohavetheright
signonbothsidesoftheequilibriumpointyoumustthinkaboutandwritethattermproperly.
Considerwhatwasdoneforquadraticdragonprojectilestohelpyouout.]
(B) UsingMatlab,generateaplotofdisplacementasafunctionoftimeforthisdampedoscillatorin
thetimeperiod0to20seconds.Assumeinitialconditionsofx .uu mandx u) = u
m
s
.
(C) UsingMatlab,generateaplotofx vs.x(phaseplot)forthegiveninitialconditionsinpartB.

Exercise1Solution:
motioncomesfromNewtonslawsF

= mowherewehavea1D,damped
oscillator.ThesumofallforcesontheoscillatorisF = -kx - bx wherekisthespringstiffness
nt.
mx = -kx - bx

x +
b
m
PartA:Theequationof
constantandbisthedragcoefficientwhichisvelocitydepende Theequationofmotionisthusly
writtenas
x +
k
m
x = u.

efiningtheconstants[ =
b
2m
D and
o
2
=
k
m
theexpressionreducestothefinalexpressionof
x

PartB:Thesolutionstothedifferentialequationrequireknowledgeofthedampingparameter,,in
relationto
o
.Withthenumbersgiveninthestatementoftheproblem,[
2
= u.1S(1/s)
2
and
o
2
= 2S
2 2 2

(
where
1
=
o
2
- [
2
+ 2[x +
o
2
x = u.
(rad/s) .Sincethe[ issmallerthan
o
,thesystemisunderdampedandthegeneralsolutiontakeson
theform
x t) = Ac
-[t
cos (
1
t - o)
.

MHW3_1B

Function to plot Matlab HW solution for Assignment 3 for Fall 2008
icient
cillator


eter
quency" of damped oscillator

function

%
% William Tireman
% October 2, 2008

eters % Set initial param
b=3.0; % drag coeff
0.; % mass of os m=1
k=250.; % spring stiffness constant
A=1.0; % initial amplitude
beta=b/(2*m); % damping param
wo=sqrt(k/m); % natural frequency
ular fre w1=sqrt(wo^2-beta^2); %"ang

% Calculate the necessary values
t=1:0.05:20.; % time vector
*exp(-beta.*t).*cos(w1.*t); % displacment vector x=A
top=A*exp(-beta.*t); % exponential envelope top side
bottom=-top; % bottom side

% Generate the plot
plot(t,x,'.r',t,top,'--k',t,bottom,'--k')
rdamped, spring-mass SHO')
bel('Time (s)'
nt (m)')

PartC:FortheMatlabODEsolution,wegobacktotheDiffyQ
x + 2[x +
2
x = u
Inthefunctionfile,wegenerateand
o
andpasstothederivativefile.Fromtherewedefine
Jx

% Make it pretty
title('Displacement versus time for an unde
xla )
ylabel('Displaceme

o
Jt
= :
x

J:
x
Jt
= x
Therefore,ourderivativevectorintheMatlabfunctionfilewilllooklikethefollowing.
Jcri:s = |y(2); -2 - [ - y(2) -
o
2
- y(1)]
% This function uses the Matlab function ODE## to solve the simple harmonic
% oscillator with damping effects which are linear in the velocity.
ass to derivative file ... this can also be done
Function damposcmain
%
% Author: William Tireman
% Date: 9/25/08

clear all
ables to p % Set global vari
% via the ode call as well
o
)
equency of undamped system
tions=odeset('RelTol',1e2);
[position; vel.];

[]); % call to function ODE
s([0.0 max(t) -max(y(:,1)) max(y(:,1))]) % scale the axis correctly
)')
Author: William Tireman
his function delievers th derivatives back to the main function for a
r.
ivs=[y(2) -2*bb*y(2)-wo^2*y(1)];
global bb w
% Constants (can be modified for different scenarios)
N/m) k=250.0; % spring constant (
of system (kg m=10.0; % mass
b=3.0; % damping constant (kg/s)
equation of motion bb=b/(2*m); %beta constant for the
fr wo=sqrt(k/m); % natural angular

% Call to function ode45 in matlab
%
%op
ic=[.50; 0.0]; % initial conditions
n=[0.0 20.0]; % set the time stop and starts tspa
[t,y] = ode45(@damposc,tspan,ic,

% Plot the displacement versus time solution
plot(t,y(:,1),'.b')
axi

% Make it look pretty
title('Damped Harmonic Oscillator Displacement versus Time')
bel('Time (s)') xla
ylabel('Displacement (m

function derivs=damposc(t,y)

%
% Date: 9/25/08
e % T
% damped harmonic oscillato

global bb wo

der ;

0 2 4 6 8 10 12 14 16 18 20
-0.5
-0.4
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
Damped Harmonic Oscillator Displacement versus Time
Time (s)
D
i
s
p
l
a
c
e
m
e
n
t

(
m
)
Exercise2Solutions:
PartA:Thiscanbedonebywritingthedragforceas
F

= -cx |x |
Theequationofmotionthenbecomes
x +
c
m
x |x | +
k
m
x = u
Letusdefineo =
c
2m
and
o
2
=
k
m
therebyreducingtheequationto
x + ox |x | +
o
2
x = u.

PartB:JustlikePartCofthepreviousproblem,wecanwritethe2
nd
orderdiffyQastwo1
st
order
Jcri:s = |y(2); -2 - o - y(2) - obs(y(2)) -
o
2
- y(1)]
function damposc2main
% This function uses the Matlab function ODE## to solve the
% oscillator with velocity squared damping effects
illia reman
% Date: 9/25/08

clear all
Set the global variables to pass stuff to derivative function
global alpha wo
mass of system (kg)
/m/s)
for the equation of motion
wo=sqrt(k/m); % natural angular frequency of undamped system



',1e2);
tion ODE
ment versus time
')
ax(t) -max(y(:,1)) max(y(:,1))]) % scale the axis correctly
equations.
Thederivativefunctionthenlookslike

%
% Author: W m Ti
%
% Constants (can be modified for different scenarios)
k=4.0; % spring constant (N/m)
m=1.0; %
c=0.40; % damping constant (kg
alpha=c/(2*m); %beta constant
% Call to function ode45 in matlab
%
%options=odeset('RelTol
ic=[1.0; 0.0]; % initial conditions [position; vel.];
tspan=[0.0 20.0];
y] = ode45(@damposc2,tspan,ic,[]); % call to func [t,

f displace % Make the plot o
t(t,y(:,1),'.m plo
axis([0.0 m

% Make it look pretty
t(y(:,1),y(:,2),'b')
)
abs(y(2))-wo^2*y(1)];
title('Damped Oscillator Displacement versus Time')
xlabel('Time (s)')
ylabel('Displacement (m)')

% Make a phase plot
figure
plo
title('Damped Oscillator Phase Plot'
xlabel('Displacement (m)')
ylabel('Velocity (m/s)')

function derivs=damposc2(t,y)

% Author: William Tireman
% Date: 9/25/08
% This function delievers the derivatives back to the main function for a
% damped harmonic oscillator. (velocity squared dependence)

global alpha wo

derivs=[y(2); -2*alpha*y(2)*

Damped Oscillator Displac


1
0 2 4 6 8 10 12 14 16 18 20

-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
ement versus Time
Time (s)
n
t

(
m
)
D
i
s
p
l
a
c
e
m
e
-0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
-2
-1.5
-1
-0.5
0
0.5
1
1.5
Damped Oscillator Phase Plot
Displacement (m)
V
e
l
o
c
i
t
y

(
m
/
s
)