hw1_soln[1]
TRANSCRIPT
-
8/3/2019 hw1_soln[1]
1/9
EE128ProblemSet1Solutions
JustinHsia
UniversityofCaliforniaatBerkeley,Fall2008
Problem1:LotkaVolterraPredatorPreyEquations. CountVitoVolterrawasanItalianmathematician(1860
1940),whodevelopedamathematicalmodeltoexplaintheresultsofastatisticalstudyoffishpopulationsinthe
AdriaticSea. Inparticular,hismodelexplainstheincreaseinpredatorfish(andcorrespondingdecreaseinprey
fish)whichheobservedduringtheWorldWarIperiod. Volterraproducedaseriesofmodelsfortheinteractionof
twoormorespecies. AlfredJ.LotkawasanAmericanbiologistandactuarywhoindependentlyproducedmanyof
thesamemodels.
Oneofthesimplestoftheirmodelstakesthef mor :
(1) 2)where 0denotesthesardine(prey)populationand 0denotestheshark(predator)population. ,,,and
areallpositiveconstants. Notethattheequationsmodelthefactsthat:sardinesmultiplyfasterasthey
increase
in
number;
the
number
of
sardines
decreases
as
both
the
sardine
and
shark
population
increases;
sharks
increaseinnumberatarateproportionaltothenumberofsharksardineencounters.
(
(a)D ilibriaofthissy etermine all equ stem. (2pts)
Set 00andweget, ,whichleadstothefollowingtwoequilibriumpoints:
=
=
ba
cdee
/
/,
0
021
(b)Linearizethesystemabouteachequilibriumthatyoufoundinpart(a),andwritetheresultsintheformofa
first rentialequation
. (4pts)order vectordiffe
Let, , andtakethepartialderivatives: Plugginginthevaluesat,weget: x
d
ax
=
0
0&
Plugginginthevaluesat,weget: xbac
cbdx
=
0/
/0&
(c)Program
your
model
into
MATLAB,
choosing
representative
values
of
a,
b,
c,
and
d.
Show,
using
simulation,
how
thesharkandsardinepopulationsevolveforthefollowingthreeinitialconditions:(3pts)
nosardines,afewsharks afewsardines,nosharks d/csardines,a/bsharks
Thekeytothisproblemisrewritingthelinearizedequationsintermsof andNOT (rememberthat , and ,):
-
8/3/2019 hw1_soln[1]
2/9
For, 0 and 0 . Sow t 0 .ege 0 For, and . Soweget
= 0 // 0 //.
Therewere3differentwaystogoaboutthisinMATLAB. Iusedthearbitraryvaluesa=1.5,b=0.5,c=
0.4,d=0.8. Differentvaluesofthesenumberswillsimplychangetherateofdecay/growthofthe
populationsaswellastheinitialconditionsforthe3rdsituation. Forthefirsttwosetsofinitial
conditions,Iused5torepresentafew.
1) Simulink
Figure1:SimulinkblockdiagramofLotkaVolterrapredatorpreyequations
WS2
e2
WS1
e1
WS0
time
State -Space 2
x' = Ax+Bu
y = Cx+Du
State -Space 1
x' = Ax+Bu
y = Cx+Du
Scope 2
Scope 1
Constant
1
Clock
The
top
blocks
are
for
equilibrium
1(0,0)
and
the
bottom
blocks
are
for
equilibrium
2(d/c,
a/b).
ThestatespaceAmatricesareconstructedasshownabove. TheinputtoStateSpace1isirrelevant
becausetheBandDmatricesarezeroedout,soIhookedituptotheinputofStateSpace2. Theinput
toStateSpace2DOESmatterandissetto1sothattheBmatrixissettothestandalonematrixshown
aboveintheequationforfor. Inbothcases,theCmatrixwaschosentobe1 00 1sothattheTWOoutputvariablesarejustthestatevariables. Theoutputsarethenscopedforquickviewingandsentto
theworkspaceforbetterplotting.
TheinitialconditionsneedtobechangedinBOTHstatespaceblocksinbetweensimulations.
2) lsimThe
following
code
is
set
up
essentially
the
same
as
the
Simulink
diagram
described
above.
Everythingiswrittenout,sothematricesforthestatespaceblocksabovewillmatchthematricesthat
aretheinputstothess()functioncalls. Thistime,however,weneedtomanuallydefinethetimeand
inputvectors. Again,theinputtosys2needstobe1foralltime,andforconvenience,wewillfeedthe
sameinputsignalintosys1,eventhoughitisirrelevantinthatcase.
Tosavespace,Ihaveexcludedallcoderelatedtolabelingthegraphs(xlabel,ylabel,title,
legend).
-
8/3/2019 hw1_soln[1]
3/9
%% EE128 Problem Set 1, 1c (lsim) hw1_1c_lsim.m
%% Justin Hsia - Fall 2008%% - Creates the linearized state-space models around e1 and e2, then runs%% - all 3 sets of ICs on both systems using lsim and plots on figuresa = 1.5; b = 0.5; c = 0.4; d = 0.8;
sys1 = ss([a 0; 0 -d],[0; 0],[1 0; 0 1],[0; 0]); %e1sys2 = ss([0 -b*d/c; a*c/b 0],[a*d/c; -a*d/b],[1 0; 0 1],[0; 0]); %e2
t = 0:0.01:10; %time stepsu = ones(1,length(t)); %input is 1 over all time
x0(:,1) = [0; 5]; % set the initial conditionsx0(:,2) = [5; 0];x0(:,3) = [d/c; a/b];
for i=1:3 % loop across ICsy1 = lsim(sys1,u,t,x0(:,i));
y2 = lsim(sys2,u,t,x0(:,i));
figure(2*i-1); % plot on separate figuresplot(t,y1);figure(2*i);plot(t,y2);
end
3) ode23Touseode23,youneedtodefineseparatefunctionstorepresentbothsystems. Asyoucansee,
theyarethesamelinearizedequationsasseenintheothertwomethods:
%% EE128 Problem Set 1, 1c (ode23) eq1.m
function [xdot] = eq1(t,x)global a b c dxdot = [a 0; 0 -d]*x;
end
%% EE128 Problem Set 1, 1c (ode23) eq2.m
function [xdot] = eq2(t,x)global a b c dxdot = [0 -b*d/c; a*c/b 0]*x + [a*d/c; -a*d/b];
end
Andnow
we
call
on
these
functions
using
ode23
in
aloop.
The
only
major
difference
is
that
the
initialconditionsarenowrowvectorsinsteadofcolumnvectors.
Again,alllabelingcodehasbeenexcluded.
-
8/3/2019 hw1_soln[1]
4/9
%% EE128 Problem Set 1, 1c (ode23) hw1_1c_ode23.m
%% Justin Hsia - Fall 2008%% - Uses separate function (defined elsewhere) to represent e1 and e2,
%% - then runs all 3 sets of ICs using ode23 and plots on figuresglobal a b c d
a = 1.5; b = 0.5; c = 0.4; d = 0.8;
x0 = [0 5; 5 0; d/c a/b]; % set the initial conditions
for i=1:3 % loop across ICs[t1 x1] = ode23('eq1',[0 10],x0(i,:));[t2 x2] = ode23('eq2',[0 10],x0(i,:));
figure(2*i-1)plot(t1,x1);figure(2*i)plot(t2,x2);
end
Thegraphsareonthefollowingpage. Butwhatdoweexpecttosee?
Nosardines,afewsharksLifecannotspringupoutofnowhere. Thesardinepopulationshouldremainatzeroandthe
sharks,deprivedoftheirfoodsource,shoulddieout.
Afewsardines,nosharksThesharkpopulationshouldremainatzeroandthesardinepopulation,leftuncheckedby
predators,shouldgrowoutofcontrol(exponentially).
d/csardines,a/bsharksThisinitialconditionisdefinedtomatchoneoftheequilibriumpointsyousolvedforparta.
Sinceitisanequilibriumpoint,youexpectthepopulationstoremainthesame.
Sowhythedifferenceinsimulations?
Theimportantpointtotakeawayhereisthatlinearizationonlyworksaroundthechosen
operating(equilibrium)point. Inthefirsttwoinitialconditions,weexpectatleastoneofthe
populationstobeatzero,whichmatchesupbetterwiththefirstequilibriumpoint. Lookingatthe
linearizedmatricesA1andA2,thesardineandsharkpopulationschangebasedontheirOWN
populationsin
A1,
while
they
change
based
on
the
OTHER
population
in
A2.
This
is
why
azero
population
staysatzerousingequilibriumpoint1andwhyitdoesntstayatzerousingequilibriumpoint2. Youend
upgettingnegativepopulationsusingequilibriumpoint2,whichdoesntmakephysicalsense.
Inthethirdinitialcondition,weareattheotherequilibriumpoint,sooursecondlinearization
worksperfectly. Usingthefirstlinearization,thesharkpopulationalwaysdiesout(d)andthesardine
population,ifnotatzero,willalwaysgrowuncontrollably(a).
-
8/3/2019 hw1_soln[1]
5/9
Figure2: 0sardines,5sharksusingequilibrium 1 Figure3: 0sardines,5sharksusingequilibrium2
Figure4: 5sardines,0sharksusingequilibrium1 Figure5: 5sardines,0sharksusingequilibrium2
Figure6: 2sardines,3sharksusingequilibrium1 Figure7: 2sardines,3sharksusingequilibrium2
0 1 2 3 4 5 6 7 8 9 10-0.5
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
Time
Population
Initial Condition 1 on System 1
sardines
sharks
0 1 2 3 4 5 6 7 8 9 10-4
-2
0
2
4
6
8
Time
Population
Initial Condition 1 on System 2
sardines
sharks
0 1 2 3 4 5 6 7 8 9 10
0
2
4
6
8
10
12
14
16x 10
6
Time
Population
Initial Condition 2 on System 1
sardines
sharks
0 1 2 3 4 5 6 7 8 9 10-4
-2
0
2
4
6
8
Time
Population
Initial Condition 2 on System 2
sardines
sharks
0 1 2 3 4 5 6 7 8 9 10
0
1
2
3
4
5
6
7x 10
6
Time
Population
Initial Condition 3 on System 1
sardines
sharks
0 1 2 3 4 5 6 7 8 9 100
0.5
1
1.5
2
2.5
3
3.5
Time
Population
Initial Condition 3 on System 2
sardines
sharks
-
8/3/2019 hw1_soln[1]
6/9
Problem2: Amagneticallysuspendedsteelball,linearized.
Thesimplifieddynamicsofamagneticallysusp e egivenby:end dsteelballar
(3)wheretheinput
representsthecurrentsuppliedtotheelectromagnet,
istheverticalpositionoftheball,which
maybe
measured
by
aposition
sensor,
isgravitationalacceleration,isthemassoftheball,andisapositiveconstantsuchthattheforceontheballduetotheelectromagnetis . Assumeanormalizationsuchthat 1.(a)Usingthestates and writedownanonlinearstatespacedescriptionofthissystem.(2pts)Wehave and ,so and :
=
2
1
22
x
u
m
cg
x
x&
(b)Whatequilibriumcontrolinput mustbeappliedto u endtheballat=1m?(2pts)s spWant
the
ball
at
=1m,
so
=1.
Now
solve
for
00. ,Weget, 0and0 ,so 1== cmgue .Sidenote: Whydowe 1?ignore Theoretically,1 1. Butthinkaboutthephysicalsystem. Wehaveasteelballsuspendedintheairbyamagneticfield. Themagneticfieldisgeneratedbyacurrentrunningthroughan
electromagnet. Whathappenswhenyourunthecurrentintheoppositedirection(negativeI)? The
magneticfieldreversesdirectionaswell. Sophysically,acurrentof1woulddotheoppositeof
levitatingtheball;itwouldpushittowardstheground.
Onfurtherthought,thelogicaboveappliesiftheballwereachargedparticle. Itsentirely
possiblethattheballwouldselfpolarizeandbeattractedtotheelectromagnetundereithermagnetic
fielddirection. Ingeneral,wewilltrytosetproblemsupinawaysothatweareinterestedinpositive
values. Ifitneedstogonegative,youprobablyshouldjustredefinethedirection.
(c)Writethelinearizedstatespaceequationsforstateandinputvariablesrepresentingperturbationsawayfrom
thee ib f ( )quil riumo part b).(4pts
Let , , . d s:
Takethepartial erivative
,,,, 2
,,,, ;
,,,, 0
; 2
,,,,
0 1/ / 0/ uxu
m
cx
m
cx
+
=
+
=
2
0
02
1020
02
10&
-
8/3/2019 hw1_soln[1]
7/9
Problem3: Linearity.
(a)ForeachofthefollowingsystemsH,indicatewhetherornotthesystemis(i)Linear,(ii)TimeInvariant. Justify
youranswers. (2ptseach)
Linearity: Showthat Timeinvariance: Showthat
.output
of
delayed
input
is
same
as
delaying
regular
output)
(
i)
ii) Nonlinear
TimeInvar.
iii)
Nonlinear
,
TimeInvar.
iv)
Linear
TimeInvar.
Linear
Thisoneisalittleconfusingfortimeinvariance. Thinkaboutitvisually:ifyoudelaya
signalbyandthenreversethesignalintime,itsthesameasreversingthesignalintimeandG
.
TimeVar.
thenADVANCIN thesignalby
v) Linear
(b)Consideranamplifierhavinginputvoltageandoutputvoltagerelatedby 8. Showthat linear.Derivealinearizedmodelaroundoperatingpoint , . (3pts)
TimeVar.
theamplifierisnot
Let
,andchecklinearity:
8 8 8Linearizeequatio a u :n bo t ,
Nonlinear
; 16 16 ) )iQiiQoQo vtvvvtv = )(16)(
-
8/3/2019 hw1_soln[1]
8/9
Problem4: Transferfunction dels erivethetransferfunctionsmo . D
(i)and(ii)below.Assumethat>0,>0denoteresistorvalues,and>0denotescapacitorforeachoftheRCnetworks
values. (4ptseach)
Theseproblemscanbeapproachedintwoways:1)usingthenormalelectricalsystemmodeling
equationsandthentheLaplacetransform,or2)takingtheLaplacetransformfirst(impedance)andthen
analyzingthe
system.
Iwill
show
both
methods
here.
Figure8: RCnetwork(i) Figure9: RCnetwork(i) impedance
ModelingEquations:
Definecurrentthrough cur e hrou h a r t ghtobe. tobe, r nt t g tobe , ndcur en throuWehave: , . , , Substituting: Laplace:
( )( ) CRsRRR
CsRR
sV
sV
i
o
2121
121
)(
)(
++
+=
Impedance:
Defineparallelimpedanc f n t eo a d o be.SolveforZ:
Treatasvoltagedivider:
( )( ) CRsRRRCsRR
sV
sV
i
o
2121
12 1
)(
)(
+++=
-
8/3/2019 hw1_soln[1]
9/9
Figure10: RCnetwork(ii) Figure11: RCnetwork(ii) impedance
ModelingEquations:
Singlecurrentrunning r it. int voltagetobevoltagebetweenand.throughci cu Define ermediateWehave:
,
,
Solvefor :Substituteandinequati on:
1 1 Laplace: 1 1 1
( )212
1
1
)(
)(
RRsC
CsR
sV
sV
i
o
++
+
=
Impedance:
Defineseriesimpedance tobe.ofandSolveforZ: Treatasvoltagedivider:
( )2121
1
)(
)(
RRsC
CsR
sV
sV
i
o
++
+=
Problem5. Given ,whatislim ? (1 pt)YoucanusetheFinalValueTheorem(FVT)(lim lim )toobtainlim 0.Thefineprinthere,however,isthattheFVTappliesonly exists.
if
LookingatatableofLaplaceTransforms,wecanseethat sin.lim doesnotexist