2016 4.1 introduction to odes - weill cornell medicine · lecture i: introduction to odes ordinary...
TRANSCRIPT
QuantitativeUnderstandinginBiologyModuleIV:ODEsLectureI:IntroductiontoODEs
OrdinaryDifferentialEquationsWebeganourexplorationofdynamicsystemswithalookatlineardifferenceequations.Thisisaniceintroductiontodynamicsystemsforafewreasons.First,linearsystemsare“well-behaved”inthattheycanbetreatedanalytically.Second,theuseofdiscretetimestepsindifferenceequationsallowedustoside-stepafairamountofcalculus.
Unfortunately,therealworldisnotsoconvenient,sowe’llneedtogearuptodealwithbothnon-linearsystemsandwithtruedifferentialequations.We’lltrytokeepthenecessarycalculustoaminimum,butsomewillbeneeded.Fortunately,manyoftheoperativeconceptsaresimilar,soalthoughthemathmaybealittlemoreintimidating,youarenowinagoodpositiontounderstandit.
We’llbeginbyconsideringoneofthesimplest,andmostessential,dynamicsystems,andcompareandcontrastittoitsdiscretecounterpart.Let’sreturntoanexamplewelookedatpreviously,thatofgrowthproportionaltocurrentamountorsize.Thediscreteformofthismodelis…
𝑥!!! = 𝜆 ∙ 𝑥!
…andthesolutionis…
𝑥! = 𝑐 ∙ 𝜆!
Toexpresstheideaofarateofgrowthproportionaltocurrentsizeoramountusingdifferentialequations,wewouldwrite…
𝑑𝑥𝑑𝑡
= 𝜆 ∙ 𝑥
Solvingthis(usingcalculus)givesus…
𝑑𝑥𝑥= 𝜆 ∙ 𝑑𝑡
𝑑𝑥𝑥= 𝜆 ∙ 𝑑𝑡
ln 𝑥 = 𝜆 ∙ 𝑡 + 𝐶
…whereCisanarbitraryconstantoftheintegration.
IntroductiontoODEs
©Copyright2008,2016–JBanfelder,WeillCornellMedicalCollege Page2
Thiscanbesimplifiedintotheconventionalform…
𝑥 = 𝑒!∙!!!
𝑥 = 𝑒!∙!𝑒!
𝑥 = 𝑐 ∙ 𝑒!∙!
Inthelaststepwehaveredefinedthearbitraryconstantforourconvenience.
Toreview,wehave
Discrete Continuous𝑥! = 𝑐 ∙ 𝜆! 𝑥 = 𝑐 ∙ 𝑒!∙!
Notethatinbothcasestheevolutionofourstatevariableissomevalueraisedtoapowerthathastodowithtime.Inthediscretecase,theexponentisthenumberoftimestepsinourmodelsimulation;thisisadimensionlesscountingnumber.Inthecontinuouscase,theexponentisa“scaledtime”.Itisthetimeofthesimulation,butin‘unitsof1/λ’.Youwillseethismotifveryofteninthisformandinoneother…
𝑥 = 𝑐 ∙ 𝑒! !
Inthislatterform,τisthe‘timeconstant’ofthesystem.Ithasunitsoftime,justliket,sotheratioisdimensionless.Theratiot/τissometimesreferredtoasthe“reducedtime”.
Notethatthevaluesoftheλsinthediscreetandcontinuouscaseshavedifferentinterpretations.Inthediscretemodel,avalueofλ=1yieldsasteady-statesolution;thesystemneither‘explodes’nor‘fizzles’.Whenλ>1,thesystemwillgrow,andwhen0<λ<1,thesystemwilldecay.
Inthecontinuoustimemodel,theequilibriumconditionisreachedwhenthederivativeiszero,orwhenλ=0.Negativevaluesofλgivedecayingsystemsandpositivevaluesofλgivegrowingsystems.
ExponentialDecayTheexponentialdecayisprobablythemostfundamentalmotifyou’llseewhenyoustudydifferentialequationsanddynamicsystemsingeneral.Manydynamicsystemsinnaturethatreachanequilibriumapproachitbyanexponentialdecay.Toemphasizethenatureofthedecayweusuallywrite…
𝑥 = 𝑥! ∙ 𝑒!! !
…ratherthantakingτtobenegative.
Asabove,weoftenwriteexponentialswithatimeconstantτ.τmakesourexponentdimensionless,anditisinterpretedasspecifyinghowlongittakestoreachequilibriuminoursystem.Analternativemeasureofthisthatyoumaybefamiliarwithisthehalf-life,t1/2.Ahalf-lifeandatimeconstantrepresentthesamecharacteristicofadynamicsystem,andonecaneasilyinterconvertthem.
IntroductiontoODEs
©Copyright2008,2016–JBanfelder,WeillCornellMedicalCollege Page3
Asanexampleofhowhalf-lifeandtimeconstantarerelated,we’llrevisitproteindynamics.Let’sconsiderasystemwhereweonlyareconcernedwithproteindegradationandnotproteinproduction.Wesaythattheproteinconcentrationdecaysexponentially,whichmeansthattherateofdegradationisproportionaltotheamountofproteinpresent.Thisisareasonablemodelingassumptioninmanycontexts.Wecanwrite…
𝑑𝑝𝑑𝑡
= −1𝜏𝑝
…andthesolutionis…
𝑝 = 𝑝!𝑒!!!
Arecentpapercalculatedproteindecayratesforahundredproteinsinmammaliancells(Edenetal.Nature,2011).Theyfoundintheirsystemthattheaverageproteinhalf-lifewas9hours.Let’sfindtheτforthishalf-life.Thisoccurswhentheproteinconcentrationis½ofitsinitialvalue,orwhenp=½p0
12𝑝! = 𝑝!𝑒
!!! !!
12= 𝑒!
!! !!
ln12
= −𝑡! !
𝜏
𝜏 = −𝑡! !
ln 12
Inourcaset1/2=9hrs,sowehave…
𝜏 = −9 ℎ𝑟𝑠
ln 12
= 12.98 ℎ𝑟𝑠 ≅ 13 ℎ𝑟𝑠
Nowthatyouseethatτisjustalineartransformationofthehalf-life.Itisworthgettingfamiliarwithhowquicklyexponentialdecayoccurswithrespecttoτ.Ifweplotreducedxversusreducedtime…
IntroductiontoODEs
©Copyright2008,2016–JBanfelder,WeillCornellMedicalCollege Page4
t/τ x/x0
0 1
0.693112
1.098613
2 0.1353
3 0.0498
…wecanobservethat:
• Thedecayfallstohalfitsinitialvalueinabout0.7timeconstants.• Thedecayfallstoone-thirdofitsinitialvalueinabout1.1timeconstants.• Intwotimeconstants,thevaluehasdecayedtoabout13%ofitsinitialvalue.• Inthreetimeconstants,thevaluehasdecayedtoabout5%ofitsinitialvalue.
Notethatanexponentialdecaynever“finishes”asitasymptoticallyapproacheszero.However,asitisusefultothinkaboutdynamicevents,wecanmakeanarbitrarydefinitionabouthowmuchofadecayhastohavebeenachievedbeforeaneventis‘over’.Ifwedefinetheendofaneventasthetimewhenitreaches95%recoverytotheequilibriumvalue,weseethateventstakeaboutthreetimeconstants.Ifyouwanttouseadifferentcutoff,thatisOK.Whatisimportantisthatthelengthofaneventisontheorderofafewtimeconstants.Forexample,ifyoudefineyourcutoffas99.44%recovery,you’llfindthateventslast5.2timeconstants.Thislineofreasoningleadsustotheveryimportantrealizationthatτtellsus“howlongstufftakestohappeninoursystem”.
Notethatexponentialdecaysdon’talwaysdecaytowardszero,anddon’talwaysdecayfromhighervaluestolowervalues.Forexample,considerthesystem
𝑑𝑥𝑑𝑡
= −𝜆 ∙ 𝑥 − 𝑥!
Thegeneralsolutiontothissystemis…
𝑥 = 𝑥! + 𝑐 ∙ 𝑒!!∙!
Afewparticularsolutionstothissystemfordifferentvaluesofx0,c,andtareshowninthefigurebelow.Frominspectionoftheplotonly,youshouldbeabletoestimateτforthered(bottom)andblue(middle)curves.Thegreen(upper)curvemaybealittletrickierbecauseitisdifficulttoestimatebyeyewhatvaluethecurveisasymptoticallyapproaching;howmightyoureliablydetermineτforthiscase?[Ans:fromtoptobottom,τ=2,0.5,1].
IntroductiontoODEs
©Copyright2008,2016–JBanfelder,WeillCornellMedicalCollege Page5
FormulatingSystemsofODEsTheartofmodelingdynamicsystemsusuallybeginswithadescriptionofasystemandatransformationofthatdescriptionintoasetofdifferentialequations.Ifthesystemconsidersspatialvariabilityinadditiontotemporalvariability,youwillusuallyendupwithasetofpartialdifferentialequations.Forthissectionoftheclasswewillfocusonsystemsthatdonotconsiderspatialvariability,andthereforewillresultinordinarydifferentialequations.
Let’sconsideranexampleofhowasystemofODEscanbeformulatedfromasystemdescription.We’llreturntoourbasicenzyme-substratesystem:
𝐸 + 𝑆!!,!!! 𝐸𝑆
!! 𝐸 + 𝑃
Wecanwritethedifferentialequationofeachspeciesbysimpleapplicationofthelawofmassaction.
𝑑[𝐸]𝑑𝑡
= −𝑘! 𝐸 𝑆 + 𝑘!! 𝐸𝑆 + 𝑘![𝐸𝑆]
𝑑[𝑆]𝑑𝑡
= −𝑘! 𝐸 𝑆 + 𝑘!! 𝐸𝑆
IntroductiontoODEs
©Copyright2008,2016–JBanfelder,WeillCornellMedicalCollege Page6
𝑑 𝐸𝑆𝑑𝑡
= 𝑘! 𝐸 𝑆 − 𝑘!! 𝐸𝑆 − 𝑘![𝐸𝑆]
𝑑 𝑃𝑑𝑡
= 𝑘![𝐸𝑆]
Weshouldnotethattheabovedifferentialequationsassumethesystemisatconstantvolume.Asthisisnotachemistryclass,wewilljustacceptthis.
Tosimulatetheabovesystem,weneedthemodelparameters.Inthiscase,therearethree:k1,k-1,andk2.Wealsoneedinitialconditionsforthestatevariables.Inthiscase,fourwouldbeneeded:[E]0,[S]0,[ES]0,and[P]0.
RunningaSimulation:BasicTheoryThemostcommonwayofthinkingaboutrunningasimulationofasystemofODEsistheEulermethod.We“discretize”thesystembyturningthedifferentialequationsintothedifferenceequationanalogs.Thediscreteanalogofthelastequationinoursystemwouldbe…
Δ 𝑃Δ𝑡
= 𝑘! ⋅ [𝐸𝑆]
𝑃 !!! − 𝑃 ! = 𝑘! ⋅ 𝐸𝑆 ! ⋅ Δ𝑡
𝑃 !!! = 𝑃 ! + 𝑘! ⋅ 𝐸𝑆 ! ⋅ Δ𝑡
Asimilartechniquecanbeappliedtotheotherequationsinthesystem.Thesedifferenceequationscanbesolvedquitestraightforwardlybysimpleiteration.Ifweareluckyandtheresultantsystemofequationsislinearandcanbecastinmatrixform,wecanbringthetechniqueswelearnedintheprevioussectiontobear.Unfortunately,thisisnotthecaseinthissystem.Thesecondequationdiscretizesasfollows:
Δ 𝑆Δ𝑡
= −𝑘! 𝐸 𝑆 + 𝑘!![𝐸𝑆]
𝑆 !!! = 𝑆 ! − 𝑘! 𝐸 ! S ! ⋅ Δ𝑡 + 𝑘!! 𝐸𝑆 ! ⋅ Δ𝑡
Sadly,theproductofthetwostatevariablesprecludesalinear,matrixformulationofthesystem.
Oncewehavediscretizedourdifferentialequations,wecanchooseasufficientlysmallΔtanduseacomputertoiterateovertime.
Thismethod,elegantandsimpleasitis,hasapitfall.Thedevilisinthephrase‘sufficientlysmall’.Oftensufficientlysmallmeansreally,reallysmall.Sometimesitisimpracticallysmall.Thebiggestimpactofthisisoftencomputertime;youmayneedlotsofstepstoiterateyoursystem.However,toosmallcangetyouintotroublewiththefloatingpointaccuracyofyourcomputertoo.Additionally,thesimpleEulerintegrationmethodcanintroducesystematicerrors.
IntroductiontoODEs
©Copyright2008,2016–JBanfelder,WeillCornellMedicalCollege Page7
Toseetheproblem,let’sconsidertheexampleofasimpleexponential
𝑑𝑥𝑑𝑡
= 1 − 𝑥
Inthiscaseweknowtheanalyticalsolutiontobe(forthecasewherex0=0)
𝑥 = 1 − 𝑒!!
Thisisanexponentialapproachtox=1.Thediscreteversionofthedifferentialequationis
𝑥!!! = 𝑥! 1 − Δ𝑡 + Δ𝑡
Itiseasytoshowthatforeverystep,nomatterhowsmallΔtis,thisequationwillalwaysover-predictthechangeinx.
ItcanbeshownthatEulerintegrationhaserrorsthatareO(Δt2).Thus,togettoa“reasonable”answer,onemayneedtochooseaverysmallΔt.
RunningaSimulation:PracticalTheoryTherearemanyschemesthattrytofixtheproblem.Theso-calledpredictor-correctormethodsuseanEuler-likemethodtopredictthenewvalueofx.Thederivativeisthenevaluatedatthenewvalue,andisusedtocorrectthepredictioninsomemanner.
ProbablythemostimportantpracticalmethodforintegratingsystemsofODEsisthefourthorderRunge-Kuttamethod;thisisoftenabbreviatedasRK4.ItcanbeshownthattheRK4methodhasanerrorofO(Δt5).WhilethereareseveralRKalgorithmsofdifferentorders,RK4isthemostcommonlyused.IfsomeonesaystheyareusingtheRunge-Kuttaalgorithmwithoutspecifiyingtheorder,youcanbesuretheyareusingRK4(p<0.0001).TheequationsforRK4aregivenhereforcompletenessonly…
IntroductiontoODEs
©Copyright2008,2016–JBanfelder,WeillCornellMedicalCollege Page8
Anotherimportantenhancementistheideaofvariablestepsize.Theideaisthatifthingsarenotchangingveryquicklyinyoursimulation,youcantakelargerstepsizes.Thiscanbeahugetime-saver.Implementationofthelogictoachievevariablestepsizesisbeyondthescopeofthiscourse.
RunningaSimulation:PracticalMethodsThegoodnewsisthatMatlabimplementsRK4withvariablestepsizesoyoudon’thavetoworryaboutthedetails.ThekeytogettingMatlabtodotheheavyliftingisthatyouneedtowriteaMatlabfunctionthatgivesthederivativesofeachstatevariable.Thisfunctionisstoredinam-file.Forexample,thefollowingm-filewillgivethederivativetoanexponentialapproachtoaspecifiedvaluewithaspecifiedtimeconstant(File:test1_func.m):
function [ dydt ] = test1_func(t, y, y0, tau) %TEST1_FUNC Simple exponential decay for testing RK4 ODE solver % Provides derivatives for an exponential decay to y0 with time constant tau. dydt = [ -(y - y0)/tau ];
Then,inMatlab,withthisonthepath,wewrite…
start = 0; y0 = 5; tau = 1; tspan = [0 10]; [t y] = ode45(@test1_func, tspan, start, [], y0, tau); plot(t,y)
Itisalsoinstructivetoinspecttheoutputarraystandy.You’llseethatthetimestepisnotuniform.
Warning:plot(y)willgiveyouerroneousresults!
Amorecomplexexample–ourMichaelis-Mentenmodel(file:mm.m):
function [ dydt ] = mm( t, y, k1, k_1, k2 ) %MM derivatives for Michaelis Menten kinetics % MM kinetics: E + S <----k1,k_1----> ES --k2--> E + P % state vars are: y(1) = S, y(2) = E, y(3) = ES, y(4) = P % Fetch variables S = y(1); E = y(2); ES = y(3); P = y(4); dydt = [ -k1 * S * E + k_1 * ES; -k1 * S * E + k_1 * ES + k2 * ES; k1 * S * E - k_1 * ES - k2 * ES; k2 * ES ];
IntroductiontoODEs
©Copyright2008,2016–JBanfelder,WeillCornellMedicalCollege Page9
AndtheninMatlab:
start = [1, 0.1, 0, 0]; k1 = 0.1; k_1 = 0.1; k2 = 0.3; tspan = [0 1000]; [t, y] = ode45(@mm, tspan, start, [], k1, k_1, k2); plot(t,y); hold on; legend('S', 'E', 'ES', 'P'); Observehowquicklythecomplexformsandreachesa“quasi-equilibrium”concentration.Thenobservethattheproductformswithamuchslowertimeconstant.Imaginehowmanysimulationstepsyouwouldneedifthewholesimulationwererunwithatimestepnecessarytogetthefirstbitofthesimulationcorrect.