S IMULINK ® Dynamic System Simulation for MATLAB® Modeling Simulation Implementation Using Simulink Version 3 How to Contact The MathWorks: % 508-647-7000 Phone 508-647-7001 Fax ) TheMathWorks,Inc. Mail 24PrimeParkWay Natick,MA01760-1500 http://www.mathworks.com Web ftp.mathworks.com AnonymousFTPserver comp.soft-sys.matlab Newsgroup @ [email protected] Technicalsupport [email protected] Productenhancementsuggestions [email protected] Bugreports [email protected] Documentationerrorreports [email protected] Subscribinguserregistration [email protected] Orderstatus,licenserenewals,passcodes [email protected] Sales,pricing,andgeneralinformation UsingSimulink (cid:211) COPYRIGHT1990-1999byTheMathWorks,Inc. Thesoftwaredescribedinthisdocumentisfurnishedunderalicenseagreement. Thesoftwaremaybeused orcopiedonlyunderthetermsofthelicenseagreement.Nopartofthismanualmaybephotocopiedorrepro- ducedinanyformwithoutpriorwrittenconsentfromTheMathWorks,Inc. U.S.GOVERNMENT: IfLicenseeisacquiringtheProgramsonbehalfofanyunitoragencyoftheU.S. Government,thefollowingshallapply: (a)ForunitsoftheDepartmentofDefense: theGovernmentshall haveonlytherightsspecifiedinthelicenseunderwhichthecommercialcomputersoftwareorcommercial softwaredocumentationwasobtained,assetforthinsubparagraph(a)oftheRightsinCommercial ComputerSoftwareorCommercialSoftwareDocumentationClauseatDFARS227.7202-3,thereforethe rightssetforthhereinshallapply;and(b)Foranyotherunitoragency: NOTICE:Notwithstandingany otherleaseorlicenseagreementthatmaypertainto,oraccompanythedeliveryof,thecomputersoftware andaccompanyingdocumentation,therightsoftheGovernmentregardingitsuse,reproduction,anddisclo- sureareassetforthinClause52.227-19(c)(2)oftheFAR. MATLAB,Simulink,Stateflow,HandleGraphics,andReal-TimeWorkshopareregisteredtrademarksand theTargetLanguageCompilerisatrademarkofTheMathWorks,Inc. Otherproductorbrandnamesaretrademarksorregisteredtrademarksoftheirrespectiveholders. PrintingHistory: 1990 Firstprinting December1996RevisedforSimulink2 May1997 RevisedforSimulink2.1(onlineversion) January1998 Revisedfor Simulink2.2(onlineversion) January1999 Revisedfor Simulink3(Release11) Contents Getting Started 1 TotheReader ........................................ 1-2 WhatIsSimulink? .................................... 1-2 HowtoUseThisManual............................... 1-3 ApplicationToolboxes ................................. 1-5 TheSimulinkReal-TimeWorkshop .................... 1-10 KeyFeatures ....................................... 1-10 TheReal-TimeWorkshopAdaExtension ............... 1-12 KeyFeatures ....................................... 1-12 Blocksets ........................................... 1-14 TheDSPBlockset ................................... 1-14 TheFixed-PointBlockset ............................. 1-14 TheNonlinearControlDesignBlockset .................. 1-16 ThePowerSystemBlockset ........................... 1-16 Quick Start 2 RunningaDemoModel................................ 2-2 DescriptionoftheDemo ............................... 2-3 SomeThingstoTry ................................... 2-4 WhatThisDemoIllustrates ............................ 2-5 OtherUsefulDemos .................................. 2-5 i BuildingaSimpleModel ............................... 2-6 Creating a Model 3 StartingSimulink ..................................... 3-2 CreatingaNewModel ................................. 3-3 EditinganExistingModel .............................. 3-3 EnteringSimulinkCommands .......................... 3-3 SimulinkWindows .................................... 3-5 ZoomingBlockDiagrams ............................... 3-6 SelectingObjects...................................... 3-7 SelectingOneObject .................................. 3-7 SelectingMorethanOneObject ......................... 3-7 Blocks ............................................... 3-9 BlockDataTips ...................................... 3-9 VirtualBlocks ........................................ 3-9 CopyingandMovingBlocksfromOneWindowtoAnother .. 3-10 MovingBlocksinaModel ............................. 3-12 DuplicatingBlocksinaModel.......................... 3-12 SpecifyingBlockParameters ........................... 3-12 BlockPropertiesDialogBox ........................... 3-13 DeletingBlocks ..................................... 3-14 ChangingtheOrientationofBlocks ..................... 3-15 ResizingBlocks ..................................... 3-15 ManipulatingBlockNames ............................ 3-16 DisplayingParametersBeneathaBlock’sIcon ............ 3-17 DisconnectingBlocks ................................. 3-18 VectorInputandOutput .............................. 3-18 ScalarExpansionofInputsandParameters .............. 3-18 AssigningBlockPriorities ............................. 3-19 UsingDropShadows ................................. 3-20 Libraries ............................................ 3-21 Terminology ........................................ 3-21 ii CreatingaLibrary ................................... 3-21 ModifyingaLibrary .................................. 3-22 CopyingaLibraryBlockintoaModel ................... 3-22 UpdatingaLinkedBlock .............................. 3-23 BreakingaLinktoaLibraryBlock ..................... 3-23 FindingtheLibraryBlockforaReferenceBlock ........... 3-24 GettingInformationAboutLibraryBlocks ............... 3-24 BrowsingBlockLibraries ............................. 3-25 Lines ................................................ 3-27 DrawingaLineBetweenBlocks ........................ 3-27 DrawingaBranchLine ............................... 3-28 DrawingaLineSegment .............................. 3-28 DisplayingLineWidths ............................... 3-31 InsertingBlocksinaLine ............................. 3-31 SignalLabels ....................................... 3-32 SettingSignalProperties .............................. 3-34 SignalPropertiesDialogBox........................... 3-35 Annotations ......................................... 3-37 WorkingwithDataTypes ............................. 3-38 DataTypesSupportedbySimulink ..................... 3-38 BlockSupportforDataandNumericSignalTypes ......... 3-39 SpecifyingBlockParameterDataTypes ................. 3-43 CreatingSignalsofaSpecificDataType ................. 3-43 DisplayingPortDataTypes ........................... 3-43 DataTypePropagation ............................... 3-43 DataTypingRules ................................... 3-44 EnablingStrictBooleanTypeChecking .................. 3-45 TypecastingSignals .................................. 3-45 TypecastingParameters .............................. 3-45 WorkingwithComplexSignals ........................ 3-47 SummaryofMouseandKeyboardActions .............. 3-48 CreatingSubsystems ................................. 3-51 CreatingaSubsystembyAddingtheSubsystemBlock ..... 3-51 iii CreatingaSubsystembyGroupingExistingBlocks ........ 3-52 LabelingSubsystemPorts ............................. 3-53 UsingCallbackRoutines .............................. 3-53 TipsforBuildingModels .............................. 3-57 ModelingEquations .................................. 3-58 ConvertingCelsiustoFahrenheit ....................... 3-58 ModelingaSimpleContinuousSystem .................. 3-59 SavingaModel ...................................... 3-61 PrintingaBlockDiagram ............................. 3-62 PrintDialogBox ..................................... 3-62 PrintCommand ..................................... 3-63 SpecifyingPaperSizeandOrientation ................... 3-64 PositioningandSizingaDiagram....................... 3-64 TheModelBrowser .................................. 3-66 UsingtheModelBrowseronWindows ................... 3-66 UsingtheModelBrowseronUNIX ..................... 3-67 TrackingModelVersions ............................. 3-70 SpecifyingtheCurrentUser ........................... 3-70 ModelPropertiesDialog .............................. 3-72 CreatingaModelChangeHistory....................... 3-76 VersionControlProperties ............................ 3-77 EndingaSimulinkSession ............................ 3-79 Running a Simulation 4 Introduction .......................................... 4-2 UsingMenuCommands ............................... 4-2 RunningaSimulationfromtheCommandLine ............ 4-3 iv RunningaSimulationUsingMenuCommands........... 4-4 SettingSimulationParametersandChoosingtheSolver ..... 4-4 ApplyingtheSimulationParameters ..................... 4-4 StartingtheSimulation ................................ 4-4 SimulationDiagnosticsDialogBox ....................... 4-6 TheSimulationParametersDialogBox ................. 4-8 TheSolverPage ...................................... 4-8 TheWorkspaceI/OPage .............................. 4-17 TheDiagnosticsPage ................................. 4-24 ImprovingSimulationPerformanceandAccuracy ...... 4-27 SpeedingUptheSimulation ........................... 4-27 ImprovingSimulationAccuracy ........................ 4-28 RunningaSimulationfromtheCommandLine ......... 4-29 UsingthesimCommand .............................. 4-29 Usingtheset_paramCommand ........................ 4-29 sim ................................................ 4-30 simset ............................................. 4-32 simget ............................................. 4-36 Analyzing Simulation Results 5 ViewingOutputTrajectories ........................... 5-2 UsingtheScopeBlock ................................. 5-2 UsingReturnVariables ................................ 5-2 UsingtheToWorkspaceBlock .......................... 5-3 Linearization ......................................... 5-4 EquilibriumPointDetermination ...................... 5-7 linfun ............................................... 5-9 trim ............................................... 5-13 v Using Masks to Customize Blocks 6 Introduction .......................................... 6-2 ASampleMaskedSubsystem ........................... 6-3 CreatingMaskDialogBoxPrompts ...................... 6-4 CreatingtheBlockDescriptionandHelpText ............. 6-6 CreatingtheBlockIcon ................................ 6-6 Summary ........................................... 6-8 TheMaskEditor:AnOverview ......................... 6-9 TheInitializationPage ............................... 6-10 PromptsandAssociatedVariables ...................... 6-10 ControlTypes ....................................... 6-12 DefaultValuesforMaskedBlockParameters ............. 6-14 TunableParameters ................................. 6-14 InitializationCommands .............................. 6-15 TheIconPage ....................................... 6-18 DisplayingTextontheBlockIcon ...................... 6-18 DisplayingGraphicsontheBlockIcon ................... 6-20 DisplayingImagesonMasks ........................... 6-21 DisplayingaTransferFunctionontheBlockIcon.......... 6-22 ControllingIconProperties ............................ 6-23 TheDocumentationPage ............................. 6-26 TheMaskTypeField ................................. 6-26 TheBlockDescriptionField ........................... 6-26 TheMaskHelpTextField ............................. 6-27 CreatingDynamicDialogsforMaskedBlocks .......... 6-28 SettingMaskedBlockDialogParameters ................ 6-28 PredefinedMaskedDialogParameters .................. 6-29 vi Conditionally Executed Subsystems 7 Introduction .......................................... 7-2 EnabledSubsystems ................................... 7-3 CreatinganEnabledSubsystem ......................... 7-3 BlocksanEnabledSubsystemCanContain ............... 7-5 TriggeredSubsystems ................................. 7-8 CreatingaTriggeredSubsystem ......................... 7-9 Function-CallSubsystems ............................. 7-10 BlocksThataTriggeredSubsystemCanContain .......... 7-10 TriggeredandEnabledSubsystems .................... 7-11 CreatingaTriggeredandEnabledSubsystem............. 7-11 ASampleTriggeredandEnabledSubsystem ............. 7-12 CreatingAlternatelyExecutingSubsystems .............. 7-12 Block Reference 8 WhatEachBlockReferencePageContains .............. 8-2 SimulinkBlockLibraries .............................. 8-3 Abs ............................................... 8-11 AlgebraicConstraint ................................. 8-12 Backlash ........................................... 8-14 Band-LimitedWhiteNoise ............................ 8-18 BusSelector ........................................ 8-20 ChirpSignal ........................................ 8-22 Clock .............................................. 8-24 CombinatorialLogic .................................. 8-25 ComplextoMagnitude-Angle .......................... 8-28 ComplextoReal-Imag ................................ 8-29 ConfigurableSubsystem .............................. 8-30 Constant ........................................... 8-34 vii CoulombandViscousFriction .......................... 8-35 DataStoreMemory .................................. 8-36 DataStoreRead ..................................... 8-38 DataStoreWrite .................................... 8-39 DataTypeConversion ................................ 8-41 DeadZone .......................................... 8-43 Demux ............................................. 8-45 Derivative .......................................... 8-49 DigitalClock ........................................ 8-51 DiscreteFilter ...................................... 8-52 DiscretePulseGenerator .............................. 8-54 DiscreteState-Space ................................. 8-56 Discrete-TimeIntegrator .............................. 8-58 DiscreteTransferFcn ................................ 8-65 DiscreteZero-Pole ................................... 8-67 Display ............................................ 8-69 DotProduct......................................... 8-72 Enable ............................................. 8-74 Fcn ............................................... 8-76 First-OrderHold .................................... 8-78 From .............................................. 8-80 FromFile .......................................... 8-82 FromWorkspace .................................... 8-85 Function-CallGenerator .............................. 8-88 Gain .............................................. 8-89 Goto ............................................... 8-91 GotoTagVisibility ................................... 8-94 Ground ............................................ 8-95 HitCrossing ........................................ 8-96 IC ................................................. 8-98 Inport ............................................. 8-99 Integrator ......................................... 8-103 LogicalOperator.................................... 8-108 Look-UpTable ..................................... 8-110 Look-UpTable(2-D)................................. 8-113 Magnitude-AngletoComplex ......................... 8-116 ManualSwitch ..................................... 8-118 MathFunction ..................................... 8-119 MATLABFcn ...................................... 8-121 MatrixGain ....................................... 8-123 viii