DynamicSystemModellingandAnalysis withMATLABandPython
ForControlEngineers
JongraeKim
UniversityofLeeds Leeds,UK
IEEEPressSeriesonControlSystemsTheoryandApplications MariaDomenicaDiBenedetto,SeriesEditor
Copyright©2023byTheInstituteofElectricalandElectronicsEngineers,Inc.Allrights reserved.
PublishedbyJohnWiley&Sons,Inc.,Hoboken,NewJersey.
PublishedsimultaneouslyinCanada.
Nopartofthispublicationmaybereproduced,storedinaretrievalsystem,ortransmittedinany formorbyanymeans,electronic,mechanical,photocopying,recording,scanning,orotherwise, exceptaspermittedunderSection107or108ofthe1976UnitedStatesCopyrightAct,without eitherthepriorwrittenpermissionofthePublisher,orauthorizationthroughpaymentofthe appropriateper-copyfeetotheCopyrightClearanceCenter,Inc.,222RosewoodDrive,Danvers, MA01923,(978)750-8400,fax(978)750-4470,oronthewebatwww.copyright.com.Requeststo thePublisherforpermissionshouldbeaddressedtothePermissionsDepartment,JohnWiley& Sons,Inc.,111RiverStreet,Hoboken,NJ07030,(201)748-6011,fax(201)748-6008,oronlineat http://www.wiley.com/go/permission.
LimitofLiability/DisclaimerofWarranty:Whilethepublisherandauthorhaveusedtheirbest effortsinpreparingthisbook,theymakenorepresentationsorwarrantieswithrespecttothe accuracyorcompletenessofthecontentsofthisbookandspecificallydisclaimanyimplied warrantiesofmerchantabilityorfitnessforaparticularpurpose.Nowarrantymaybecreatedor extendedbysalesrepresentativesorwrittensalesmaterials.Theadviceandstrategiescontained hereinmaynotbesuitableforyoursituation.Youshouldconsultwithaprofessionalwhere appropriate.Further,readersshouldbeawarethatwebsiteslistedinthisworkmayhave changedordisappearedbetweenwhenthisworkwaswrittenandwhenitisread.Neitherthe publishernorauthorshallbeliableforanylossofprofitoranyothercommercialdamages, includingbutnotlimitedtospecial,incidental,consequential,orotherdamages. Forgeneralinformationonourotherproductsandservicesorfortechnicalsupport,please contactourCustomerCareDepartmentwithintheUnitedStatesat(800)762-2974,outsidethe UnitedStatesat(317)572-3993orfax(317)572-4002. Wileyalsopublishesitsbooksinavarietyofelectronicformats.Somecontentthatappearsin printmaynotbeavailableinelectronicformats.FormoreinformationaboutWileyproducts, visitourwebsiteatwww.wiley.com.
LibraryofCongressCataloging-in-PublicationDataAppliedfor: Hardback:9781119801627
CoverDesign:Wiley
CoverImages:©BocskaiIstvan/Shutterstock
Setin9.5/12.5ptSTIXTwoTextbyStraive,Chennai,India
ToMiyoung
Contents
Preface xiii
Acknowledgements xv
Acronyms xvii
AbouttheCompanionWebsite xix
1Introduction 1
1.1ScopeoftheBook 1
1.2MotivationExamples 2
1.2.1Free-FallingObject 2
1.2.1.1FirstPrograminMatlab 4
1.2.1.2FirstPrograminPython 10
1.2.2Ligand–ReceptorInteractions 14
1.3OrganizationoftheBook 21 Exercises 21 Bibliography 22
2AttitudeEstimationandControl 23
2.1AttitudeKinematicsandSensors 23
2.1.1SolveQuaternionKinematics 26
2.1.1.1MATLAB 26
2.1.1.2Python 29
2.1.2GyroscopeSensorModel 33
2.1.2.1Zero-MeanGaussianWhiteNoise 33
2.1.2.2GenerateRandomNumbers 34
2.1.2.3StochasticProcess 40
2.1.2.4MATLAB 41
2.1.2.5Python 45
2.1.2.6GyroscopeWhiteNoise 49
2.1.2.7GyroscopeRandomWalkNoise 50
2.1.2.8GyroscopeSimulation 53
2.1.3OpticalSensorModel 57
2.2AttitudeEstimationAlgorithm 64
2.2.1ASimpleAlgorithm 64
2.2.2QUESTAlgorithm 65
2.2.3KalmanFilter 66
2.2.4ExtendedKalmanFilter 75
2.2.4.1ErrorDynamics 76
2.2.4.2BiasNoise 77
2.2.4.3NoisePropagationinErrorDynamics 78
2.2.4.4StateTransitionMatrix, Φ 84
2.2.4.5VectorMeasurements 84
2.2.4.6Summary 86
2.2.4.7KalmanFilterUpdate 86
2.2.4.8KalmanFilterPropagation 87
2.3AttitudeDynamicsandControl 88
2.3.1DynamicsEquationofMotion 88
2.3.1.1MATLAB 91
2.3.1.2Python 94
2.3.2ActuatorandControlAlgorithm 95
2.3.2.1MATLABProgram 98
2.3.2.2Python 101
2.3.2.3AttitudeControlAlgorithm 103
2.3.2.4AltitudeControlAlgorithm 105
2.3.2.5Simulation 106
2.3.2.6MATLAB 107
2.3.2.7RobustnessAnalysis 107
2.3.2.8ParallelProcessing 110 Exercises 113 Bibliography 115
3AutonomousVehicleMissionPlanning 119
3.1PathPlanning 119
3.1.1PotentialFieldMethod 119
3.1.1.1MATLAB 122
3.1.1.2Python 126
3.1.2GraphTheory-BasedSamplingMethod 126
3.1.2.1MATLAB 128
3.1.2.2Python 129
3.1.2.3Dijkstra’sShortestPathAlgorithm 130
3.1.2.4MATLAB 130
3.1.2.5Python 131
3.1.3ComplexObstacles 134
3.1.3.1MATLAB 135
3.1.3.2Python 141
3.2MovingTargetTracking 145
3.2.1UAVandMovingTargetModel 145
3.2.2OptimalTargetTrackingProblem 148
3.2.2.1MATLAB 149
3.2.2.2Python 151
3.2.2.3Worst-CaseScenario 153
3.2.2.4MATLAB 157
3.2.2.5Python 159
3.2.2.6OptimalControlInput 164
3.3TrackingAlgorithmImplementation 167
3.3.1Constraints 167
3.3.1.1MinimumTurnRadiusConstraints 167
3.3.1.2VelocityConstraints 169
3.3.2OptimalSolution 172
3.3.2.1ControlInputSampling 172
3.3.2.2InsidetheConstraints 175
3.3.2.3OptimalInput 177
3.3.3VerificationSimulation 180 Exercises 182 Bibliography 182
4BiologicalSystemModelling 185
4.1BiomolecularInteractions 185
4.2DeterministicModelling 185
4.2.1GroupofCellsandMultipleExperiments 186
4.2.1.1ModelFittingandtheMeasurements 188
4.2.1.2FindingAdaptiveParameters 190
4.2.2 E.coli TryptophanRegulationModel 191
4.2.2.1Steady-StateandDependantParameters 194
4.2.2.2PadéApproximationofTime-Delay 195
4.2.2.3State-SpaceRealization 196
4.2.2.4Python 205
4.2.2.5ModelParameterRanges 206
4.2.2.6ModelFittingOptimization 213
4.2.2.7OptimalSolution(MATLAB) 221
4.2.2.8OptimalSolution(Python) 223
4.2.2.9AdaptiveParameters 226
4.2.2.10Limitations 226
x Contents
4.3BiologicalOscillation 227
4.3.1Gillespie’sDirectMethod 231
4.3.2SimulationImplementation 234
4.3.3RobustnessAnalysis 241 Exercises 245 Bibliography 246
5BiologicalSystemControl 251
5.1ControlAlgorithmImplementation 251
5.1.1PIController 251
5.1.1.1IntegralTerm 252
5.1.1.2ProportionalTerm 253
5.1.1.3SummationoftheProportionalandtheIntegralTerms 253
5.1.1.4ApproximatedPIController 253
5.1.1.5ComparisonofPIControllerandtheApproximation 254
5.1.2ErrorCalculation: ΔP 260
5.2RobustnessAnalysis: �� -Analysis 269
5.2.1SimpleExamples 269
5.2.1.1 �� UpperBound 272
5.2.1.2 �� LowerBound 275
5.2.1.3ComplexNumbersinMATLAB/Python 278
5.2.2SyntheticCircuits 280
5.2.2.1MATLAB 281
5.2.2.2Python 281
5.2.2.3 �� -UpperBound:GeometricApproach 290 Exercises 291 Bibliography 292
6FurtherReadings 295
6.1BooleanNetwork 295
6.2NetworkStructureAnalysis 296
6.3Spatial-TemporalDynamics 297
6.4DeepLearningNeuralNetwork 298
6.5ReinforcementLearning 298 Bibliography 298
AppendixASolutionsforSelectedExercises 301
A.1Chapter1 301
Exercise1.4 301
Exercise1.5 301
A.2Chapter2 302
Exercise2.5 302
A.3Chapter3 302
Exercise3.1 302
Exercise3.6 303
A.4Chapter4 303
Exercise4.1 303
Exercise4.2 303
Exercise4.7 304
A.5Chapter5 304
Exercise5.2 304
Exercise5.3 304
Index 307
Preface
ThisbookisforcontrolengineerstolearndynamicsystemmodellingandsimulationandcontroldesignandanalysisusingMATLABorPython.Thereaders areassumedtohavetheundergraduatefinal-yearlevelofknowledgeonordinary differentialequations,vectorcalculus,probability,andbasicprogramming.
WehaveverifiedalltheMATLABandPythoncodesinthebookusingMATLAB R2021aandPython3.8inSpyder,thescientificPythondevelopmentenvironment. Toreducetheconfusioninrunningaparticularprogram,mostoftheprogramsare independentontheirown.Organizingprogrammingwithmultiplefilesisleftas anadvancedskillforreaderstolearnafterreadingthisbook.
Leeds,WestYorkshire,England,UK 30November2021
JongraeKim
Acknowledgements
Ihavelearneddynamicmodellingandsimulationthroughmyundergraduate andpost-graduateeducationandresearchprojectsinthepast30years.Hence, thisbookwillnotbepossiblewithouthavingmyteachers,supervisors,and collaborators.IthankDrJinhoKim,ProfessorJohnL.Crassidis,Professor JoãoP.Hespanhna,ProfessorDeclanG.Bates,DrDaizhanCheng,Professor Kwang-HyunCho,ProfessorFrankPollick,andDrRajeevKrishnadas.
JongraeKim
Acronyms
DCMdirectioncosinematrix
DNAdeoxyribonucleicacid
EKFextendedKalmanfilter
KFKalmanfilter
LHSleft-handside
LTIlineartime-invariant
mRNAmessengerRNA
mRNAPmessengerRNApolymerase
N2LNetwton’ssecondlawofmotion
ODEordinarydifferentialequation
pdfprobabilitydensityfunction
PIproportionalintegral
QUESTquaternionestimationalgorithm
RHSright-handside
RNAribonucleicacid
1.2MotivationExamples
1.2.1Free-FallingObject
Newton’ssecondlawofmotionisgivenby
where Fi isthe i-thexternalforceinNewtons(N)actingontheobjectcharacterized bythemass, m,inkg, d∕dt isthetimederivative, t isthetimeinseconds, �� isthe velocityinm/s,and m�� isthemomentumoftheobject.Newton’ssecondlawstates that thesumofallexternalforcesisequaltothemomentumchangeperunitoftime Considerafree-fallingobjectshowninFigure1.1.Thereexistsonlyoneexternalforce,i.e.thegravitationalforceactingdownwardsinthefigure.Hence,the left-handsideof(1.1)issimplygivenby ∑i Fi = Fg ,where Fg isthegravitational force.Introducetheadditionalassumptionthattheobjectiswithinthereasonable rangefromthesealevel.Withtheassumption,thegravitationalforce, Fg ,isknown tobeproportionaltothemass,andtheproportionalconstantisthegravitational accelerationconstant, g,whichisequalto9.81m/s2 inthesealevel.Therefore, Fg = mg.Replacetheleft-handsideof(1.1),i.e.
Fg
wherethedownwarddirectionissettothepositivedirection,whichistheopposite oftheusualconvention. Ithighlightsthatestablishingaconsistentcoordinatesystem atthebeginningofmodellingisvitalindynamicsystemsimulation.
Fromthekinematicrelationshipbetweenthevelocity, ��,andthedisplacement, x ,wehave dx dt = ��
wheretheoriginof x isattheinitialpositionoftheobject, m,andthepositive directionof x isdownwardsinthefigure.Theright-handsideof(1.2)becomes
mg = Fg =
Finally,theleftmostandtherightmosttermsareequaltoeachotherasfollows:
mg = d dt (m dx dt ) anditisexpandedasfollows:
mg = dm dt dx dt + m d2 x dt2
Usingtheshortnotations, m = dm∕dt, x = dx ∕dt,and x = d2 x ∕dt2 ,andafter rearrangements,thegoverningequationisgivenby ̈ x = g m m ̇
Forpurelyeducationalpurposes,assumethatthemasschangerateisgivenby ̇ m =−m + 2(1.4)
Wecanidentifynowthattherearethreeindependenttime-varyingstates,which aretheposition, x ,thevelocity, x ,andthemass, m.Alltheothertime-varying states,forexample, x and m,canbeexpressedusingtheindependentstatevariables.Definethestatevariablesasfollows:
x1 = x x2 = ̇ x x3 = m
Obtainthetimederivativeofeachstateexpressedinthestatevariableasfollows:
andthisiscalled thestate-spaceform.
Lettheinitialconditionsbeequalto x1 (0)= x (0)= 0.0m, x2 (0)= x (0)= 0.5m/s, and x3 (0)= m(0)= 5kg.Equation(1.5)canbewritteninacompactformusingthe
matrix–vectornotations.Definethestatevector, x,asfollows:
andthecorrespondingstate-spaceformiswrittenas
Thesecond-orderdifferentialequation,(1.3),andthefirst-orderdifferential equation,(1.4),arecombinedintothefirst-orderthree-dimensionalvector differentialequation,(1.6).Anyhigherorderdifferentialequationscanbe transformedintothefirst-ordermulti-dimensionalvectordifferentialequation,
̇ x = f(x).NumericalintegrationmethodssuchasRunge–Kuttaintegration (Pressetal.,2007)solvesthefirst-orderODE.Theycansolveanyhigh-order differentialequationsbytransformingthemintothecorrespondingfirst-order multi-dimensionaldifferentialequation.
1.2.1.1FirstPrograminMatlab
Wearereadytosolve(1.6)withtheinitialconditionequalto x(0)=[0.00.55.0]T , wherethesuperscript T isthetransposeofthevector.Wesolvethedifferentialequationfrom t = 0to t = 5secondsusingMatlab.Matlabincludesmany numericalfunctionsandlibrariestobeusedfordynamicsimulationandanalysis. AnumericalintegratorisoneofthefunctionsalreadyimplementedinMatlab. Hence,theonlytaskwehavetodoforsolvingthedifferentialequationisto learnhowtousetheexistingfunctionsandlibrariesinMatlab.Thecomplete programmetosolvethefree-fallingobjectproblemisgiveninProgram1.1. ProducingFigure1.2isleftasanexerciseinExercise1.1.
1 clear ; 2
3grv_const=9.81; %[m/s^2]
4init_pos=0.0; %[m]
5init_vel=0.5; %[m/s]
6init_mass=5.0; %[kg]
7
8init_time=0; %[s]
9final_time=5.0; %[s]
10time_interval=[init_timefinal_time];
11
12x0=[init_posinit_velinit_mass]; 13[tout,xout]= ode45 (@(time,state)free_falling_obj(time,state, grv_const),time_interval,x0);
14
15 figure (1); 16 plot (tout,xout(:,1))
17 ylabel (’position[m]’);