simulink入门指南2012b

更新时间:2023-05-18 05:48:01 阅读量: 实用文档 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

simulink学习,入门指南适合新手,2012b

Simulink®

GettingStartedGuide

R2012b

simulink学习,入门指南适合新手,2012b

HowtoContact

MathWorks

Web

comp.soft-sys.matlabNewsgroup

/contact_TS.htmlTechnical

suggest@

bugs@

doc@

service@

info@ProductenhancementsuggestionsBugreportsDocumentationerrorreportsOrderstatus,licenserenewals,passcodesSales,pricing,andgeneral

information508-647-7000

(Phone)

508-647-7001

(Fax)

TheMathWorks,Inc.3AppleHillDriveNatick,MA01760-2098

Forcontactinformationaboutworldwideoffices,seetheMathWorksWebsite.

Simulink®GettingStartedGuide

©COPYRIGHT1990–2012byTheMathWorks,Inc.

Thesoftwaredescribedinthisdocumentisfurnishedunderalicenseagreement.Thesoftwaremaybeusedorcopiedonlyunderthetermsofthelicenseagreement.NopartofthismanualmaybephotocopiedorreproducedinanyformwithoutpriorwrittenconsentfromTheMathWorks,Inc.

FEDERALACQUISITION:ThisprovisionappliestoallacquisitionsoftheProgramandDocumentationby,for,orthroughthefederalgovernmentoftheUnitedStates.ByacceptingdeliveryoftheProgramorDocumentation,thegovernmentherebyagreesthatthissoftwareordocumentationqualifiesascommercialcomputersoftwareorcommercialcomputersoftwaredocumentationassuchtermsareusedordefinedinFAR12.212,DFARSPart227.72,andDFARS252.227-7014.Accordingly,thetermsandconditionsofthisAgreementandonlythoserightsspecifiedinthisAgreement,shallpertaintoandgoverntheuse,modification,reproduction,release,performance,display,anddisclosureoftheProgramandDocumentationbythefederalgovernment(orotherentityacquiringfororthroughthefederalgovernment)andshallsupersedeanyconflictingcontractualtermsorconditions.IfthisLicensefailstomeetthegovernment’sneedsorisinconsistentinanyrespectwithfederalprocurementlaw,thegovernmentagreestoreturntheProgramandDocumentation,unused,toTheMathWorks,Inc.

Trademarks

MATLABandSimulinkareregisteredtrademarksofTheMathWorks,Inc.See

/trademarksforalistofadditionaltrademarks.Otherproductorbrandnamesmaybetrademarksorregisteredtrademarksoftheirrespectiveholders.

Patents

MathWorksproductsareprotectedbyoneormoreU.S.patents.Pleasesee

/patentsformoreinformation.

simulink学习,入门指南适合新手,2012b

RevisionHistory

SeptemberMarch2005Online

September2006Onlineonly

March2006Onlineonly

September2007Firstonly

March2007Secondprinting

October2008Thirdprinting

March2008Fourthprinting

September2009Fifthprinting

March2009Onlineprinting

September2010Onlineonly

April2010Onlineonly

September2011Onlineonly

March2011Sixth

September20122012Seventhprintingonly

EighthprintingprintingNewRevisedforVersionRevisedforSimulink6.3(Release6.4(Release14SP3)RevisedforRevisedforSimulinkSimulink6.52006a)6.6(Release2006b)RevisedforRevisedforSimulink(Release2007a)Simulink7.0(Release2007b)RevisedforRevisedforSimulink7.1(Release2008a)Simulink7.2(Release2008b)Revisedfor7.3(Release2009a)RevisedforSimulinkSimulink7.47.5(Release(Release2009b)2010a)RevisedforSimulink7.6(Release2010b)Revisedfor

RevisedforSimulinkSimulink7.77.8(Release(Release2011a)2011b)

RevisedforforSimulinkSimulink7.98.0(Release(Release2012a)2012b)

simulink学习,入门指南适合新手,2012b

simulink学习,入门指南适合新手,2012b

1IntroductionProductDescription...............................1-2KeyFeatures.....................................1-2Modeling,Simulation,andAnalysiswithSimulink...1-3ToolforModel-BasedDesign........................1-3ToolforSimulation................................1-4ToolforAnalysis..................................1-4InteractionwithMATLABEnvironment...............1-4Model-BasedDesign...............................1-5WhatIsModel-BasedDesign?.......................1-5Model-BasedDesignProcess........................1-6DocumentationandAdditionalResources...........1-9SimulinkOnlineHelp..............................................................1-9SimulinkExamples

WebSiteResources................................1-10

1-10

2SimulinkSoftwareBasicsStarttheSimulinkSoftware........................OpentheSimulinkLibraryBrowser..................2-2

2-2

CreateaNewSimulinkModel.......................2-4OpenanExistingModel............................2-5SimulinkUserInterface............................2-6SimulinkLibrary...................................Browser..........................2-6SimulinkEditor2-10Contents

v

simulink学习,入门指南适合新手,2012b

viContents3CreateaSimulinkModelCreateaSimpleModel.............................3-2OverviewoftheSimpleModel.......................3-2CreatetheSimpleModel...........................3-3ConnectBlocksintheSimpleModel..................3-8SimulatetheSimpleModel.........................3-12ModelingaDynamicControlSystem4DynamicControlSystemModel.....................4-2AnatomyoftheControlSystemModel...............4-3OpentheExampleModel...........................4-3OverviewoftheExampleModel......................4-4SubsystemsintheExampleModel...................4-6SubsystemsandMasks...........................................................4-10CreatingaSubsystem4-11CreateaSubsystemMask..........................4-12SimulatetheControl................................SystemModel.................4-14RuntheSimulation4-14ChangetheThermostatSetting......................4-15ChangetheAverageOutdoorTemperature............4-17ChangetheDailyTemperatureVariation..............4-19MoveDataBetweenMATLABandSimulinkModel...4-21ImportDatafromtheMATLABWorkspace............4-21ExportSimulationDatatotheMATLABWorkspace.....4-25

simulink学习,入门指南适合新手,2012b

5BasicSimulationWorkflowSimulationwithDataImportandSignalInspection..5-2DataImportandLoggingWorkflow..................5-2ExampleUsedinthisTutorial.......................5-2ImportSignalData...................................................................5-4SimulateModel5-10CompareSignals..................................5-14Create,Save,andPrintaFigure.....................5-16vii

simulink学习,入门指南适合新手,2012b

viiiContents

simulink学习,入门指南适合新手,2012b

1Introduction

“ProductDescription”onpage1-2

“Modeling,Simulation,andAnalysiswithSimulink”onpage1-3 “Model-BasedDesign”onpage1-5

“DocumentationandAdditionalResources”onpage1-9

simulink学习,入门指南适合新手,2012b

Introduction

ProductDescription

1-2SimulationandModel-BasedDesignSimulink®isablockdiagramenvironmentformultidomainsimulationandModel-BasedDesign.Itsupportssystem-leveldesign,simulation,automaticcodegeneration,andcontinuoustestandverificationofembeddedsystems.Simulinkprovidesagraphicaleditor,customizableblocklibraries,andsolversformodelingandsimulatingdynamicsystems.ItisintegratedwithMATLAB®,enablingyoutoincorporateMATLABalgorithmsintomodelsandexportsimulationresultstoMATLABforfurtheranalysis.KeyFeatures Graphicaleditorforbuildingandmanaginghierarchicalblockdiagrams Librariesdiscrete-timeofpredefinedsystemsblocksformodelingcontinuous-timeand Simulationenginewithfixed-stepandvariable-stepODEsolvers Scopesanddatadisplaysforviewingsimulationresults Projectanddatamanagementtoolsformanagingmodelfilesanddata Modelsimulationanalysisspeedtoolsforrefiningmodelarchitectureandincreasing MATLABFunctionblockforimportingMATLABalgorithmsintomodels LegacyCodeToolforimportingCandC++codeintomodels

simulink学习,入门指南适合新手,2012b

Modeling,Simulation,andAnalysiswithSimulink®

Simulation,andAnalysiswithSimulinkInthissection...

“ToolforModel-BasedDesign”onpage1-3

“ToolforSimulation”onpage1-4

“ToolforAnalysis”onpage1-4

“InteractionwithMATLABEnvironment”onpage1-4

ToolforModel-BasedDesign

WithSimulink,youcanmovebeyondidealizedlinearmodelstoexploremorerealisticnonlinearmodels,factoringinfriction,airresistance,gearslippage,hardstops,andtheotherthingsthatdescribereal-worldphenomena.

Simulinkturnsyourcomputerintoalaboratoryformodelingandanalyzingsystemsthatwouldnotbepossibleorpracticalotherwise.

Whetheryouareinterestedinthebehaviorofanautomotiveclutchsystem,theflutterofanairplanewing,ortheeffectofthemonetarysupplyontheeconomy,Simulinkprovidesyouwiththetoolstomodelandsimulatealmostanyreal-worldproblem.Simulinkalsoprovidesexamplesthatmodelawidevarietyofreal-worldphenomena(clicktheExampleslinkatthetopoftheSimulinkDocumentationCentertop-levelpage).

Simulinkprovidesagraphicaluserinterface(GUI)forbuildingmodelsasblockdiagrams,allowingyoutodrawmodelsasyouwouldwithpencilandpaper.Simulinkalsoincludesacomprehensiveblocklibraryofsinks,sources,linearandnonlinearcomponents,andconnectors.Iftheseblocksdonotmeetyourneeds,however,youcanalsocreateyourownblocks.Theinteractivegraphicalenvironmentsimplifiesthemodelingprocess,eliminatingtheneedtoformulatedifferentialanddifferenceequationsinalanguageorprogram.Modelsarehierarchical,soyoucanbuildmodelsusingbothtop-downandbottom-upapproaches.Youcanviewthesystematahighlevel,thendouble-clickblockstoseeincreasinglevelsofmodeldetail.Thisapproachprovidesinsightintohowamodelisorganizedandhowitspartsinteract.

1-3Modeling,

simulink学习,入门指南适合新手,2012b

Introduction

1-4See“Model-BasedDesign”onpage1-5formoreinformationaboutthemodelingprocess.ToolforSimulationAfteryoudefineamodel,youcansimulateitsdynamicbehaviorusingachoiceofmathematicalintegrationmethods,eitherfromtheSimulinkmenusorbyenteringcommandsintheMATLABCommandWindow.Themenusareconvenientforinteractivework,whilethecommandlineisusefulforrunningabatchofsimulations.Forexample,ifyouaredoingMonteCarlosimulationsorwanttoapplyaparameteracrossarangeofvalues,ingscopesandotherdisplayblocks,youcanseethesimulationresultswhilethesimulationruns.Youcanthenchangeparametersandseewhathappensfor“whatif”exploration.ThesimulationresultscanbeputintheMATLABworkspaceforpostprocessingandvisualization.ToolforAnalysisModelanalysistoolsincludelinearizationandtrimmingtools,whichyoucanaccessfromtheMATLABcommandline,plusthemanytoolsinMATLABanditsapplicationtoolboxes.BecauseMATLABandSimulinkareintegrated,youcansimulate,analyze,andreviseyourmodelsineitherenvironmentatanypoint.InteractionwithMATLABEnvironmentSimulinksoftwareistightlyintegratedwiththeMATLABenvironment.ItrequiresMATLABtorun,dependingonittodefineandevaluatemodelandblockparameters.SimulinkcanalsousemanyMATLABfeatures.Forexample,SimulinkcanusetheMATLABenvironmentto: Definemodelinputs. Storemodeloutputsforanalysisandvisualization. Performoperatorsfunctionsandfunctions.withinamodel,throughintegratedcallstoMATLAB

simulink学习,入门指南适合新手,2012b

Model-BasedDesign

Model-BasedDesignInthissection...

“WhatIsModel-BasedDesign?”onpage1-5

“Model-BasedDesignProcess”onpage1-6

WhatIsModel-BasedDesign?

Model-BasedDesignisaprocessthatenablesfaster,morecost-effective

developmentofdynamicsystems,includingcontrolsystems,signalprocessing,andcommunicationssystems.InModel-BasedDesign,asystemmodelisatthecenterofthedevelopmentprocess,fromrequirementsdevelopment,throughdesign,implementation,andtesting.Themodelisanexecutablespecificationthatyoucontinuallyrefinethroughoutthedevelopmentprocess.Aftermodeldevelopment,simulationshowswhetherthemodelworkscorrectly.

Whensoftwareandhardwareimplementationrequirementsareincluded,suchasfixed-pointandtimingbehavior,youcanautomaticallygeneratecodeforembeddeddeploymentandcreatetestbenchesforsystemverification,savingtimeandavoidingtheintroductionofmanuallycodederrors.

Model-BasedDesignallowsyoutoimproveefficiencyby:

Usingacommondesignenvironmentacrossprojectteams

Linkingdesignsdirectlytorequirements

Integratingtestingwithdesigntocontinuouslyidentifyandcorrecterrors Refiningalgorithmsthroughmultidomainsimulation

Automaticallygeneratingembeddedsoftwarecode

Developingandreusingtestsuites

Automaticallygeneratingdocumentation

Reusingtargetsdesignstodeploysystemsacrossmultipleprocessorsandhardware

1-5

simulink学习,入门指南适合新手,2012b

Introduction

1-6Model-BasedDesignProcessTherearesixstepstomodelinganysystem:1DefiningtheSystem2IdentifyingSystemComponents3ModelingtheSystemwithEquations4BuildingtheSimulinkBlockDiagram5RunningtheSimulation6ValidatingtheSimulationResultsYouperformthefirstthreestepsofthisprocessoutsideoftheSimulinksoftwareenvironmentbeforeyoubeginbuildingyourmodel.DefiningtheSystemThefirststepinmodelingadynamicsystemistofullydefinethesystem.Ifyouaremodelingalargesystemthatcanbebrokenintoparts,youshouldmodeleachsubcomponentonitsown.Then,afterbuildingeachcomponent,youcanintegratethemintoacompletemodelofthesystem.Forexample,thesldemo_househeatexamplemodeloftheheatingsystemofahouseisbrokendownintothreemainparts: Heatersubsystem Thermostatsubsystem ThermodynamicmodelsubsystemThemosteffectivewaytobuildamodelofthissystemistoconsidereachofthesesubsystemsindependently.

simulink学习,入门指南适合新手,2012b

Model-BasedDesign

IdentifyingSystemComponents

Thesecondstepinthemodelingprocessistoidentifythesystemcomponents.Threetypesofcomponentsdefineasystem:

Parametersthem—Systemvaluesthatremainconstantunlessyouchange States—Variablesinthesystemthatchangeovertime

Signalssimulation—InputandoutputvaluesthatchangedynamicallyduringaInSimulink,parametersandstatesarerepresentedbyblocks,whilesignalsarerepresentedbythelinesthatconnectblocks.Foreachsubsystemthatyouidentified,askyourselfthefollowingquestions:

Howmanyinputsignalsdoesthesubsystemhave?

Howmanyoutputsignalsdoesthesubsystemhave?

Howmanystates(variables)doesthesubsystemhave?

Whataretheparameters(constants)inthesubsystem?

Arethereanyintermediate(internal)signalsinthesubsystem?

Onceyouhaveansweredthesequestions,youshouldhaveacomprehensivelistofsystemcomponents,andyouarereadytobeginmodelingthesystem.ModelingtheSystemwithEquations

Thethirdstepinmodelingasystemistoformulatethemathematical

equationsthatdescribethesystem.Foreachsubsystem,usethelistofsystemcomponentsthatyouidentifiedtodescribethesystemmathematically.Yourmodelmayinclude:

Algebraicequations

Logicalequations

Differentialequations,forcontinuoussystems

Differenceequations,fordiscretesystems

1-7

simulink学习,入门指南适合新手,2012b

Introduction

1-8YouusetheseequationstocreatetheblockdiagraminSimulink.BuildingtheSimulinkBlockDiagramAfteryouhavedefinedthemathematicalequationsthatdescribeeachsubsystem,youcanbeginbuildingablockdiagramofyourmodelinSimulink.Buildtheblockdiagramforeachofyoursubcomponentsseparately.Afteryouhavemodeledeachsubcomponent,youcanthenintegratethemintoacompletemodelofthesystem.See“CreatetheSimpleModel”onpage3-3formoreinformationonbuildingtheblockdiagram.RunningtheSimulationAfteryoubuildtheSimulinkblockdiagram,youcansimulatethemodelandanalyzetheresults.Simulinkallowsyoutointeractivelydefinesysteminputs,simulatethemodel,andobservechangesinbehavior.Thisallowsyoutoquicklyevaluateyourmodel.See“SimulatetheSimpleModel”onpage3-12formoreinformationonrunningasimulation.ValidatingtheSimulationResultsFinally,youmustvalidatethatyourmodelaccuratelyrepresentsthephysicalcharacteristicsofthedynamicsystem.YoucanusethelinearizationandtrimmingtoolsavailablefromtheMATLABcommandline,plusthemanytoolsinMATLABanditsapplicationtoolboxestoanalyzeandvalidateyourmodel.

simulink学习,入门指南适合新手,2012b

DocumentationandAdditionalResources

DocumentationandAdditionalResourcesInthissection...

“SimulinkOnlineHelp”onpage1-9

“SimulinkExamples”onpage1-10

“WebSiteResources”onpage1-10

SimulinkOnlineHelp

Simulinksoftwareprovidescomprehensiveonlinehelpdescribingfeatures,blocks,andfunctionswithdetailedproceduresforcommontasks.

AccessonlinehelpfromHelpmenusandcontext-sensitiveblocklabels. FromtheSimulinkLibraryBrowser,selectHelp>SimulinkHelp.

FromtheSimulinkEditor,selectHelp>Simulink>SimulinkHelp. Right-clickaSimulinkblock,andthenselectHelp.

Frombox,right-clickthemodelaConfigurationparameterlabel,ParametersthenselectorWhat’sablockparametersThis?dialog

1-9

simulink学习,入门指南适合新手,2012b

Introduction

1-10SimulinkExamplesSimulinksoftwareprovidesavarietyofexamplemodelsthatillustratekeymodelingconceptsandSimulinkfeatures.YoucanaccesstheseexamplesfromtheHelpmenuorfromthedocumentation. FromtheSimulinkEditor,selectHelp>Simulink>Examples. Frompage.thedocumentation,clickExamplesatthetopofthe

productlandingFeaturedexamplesincludeabuttonatthetopoftheHelpbrowserforopeningthemodelin

theSimulinkEditor..WebSiteResourcesYoucanaccessadditionalSimulinkresourcesontheMathWorksWebsite,includingSimulinkrelatedbooks,webinars,andtechnicalsupport.ToaccesstheSimulinkproductpage,goto/products/simulink

simulink学习,入门指南适合新手,2012b

2

SimulinkSoftwareBasics

“StarttheSimulinkSoftware”onpage2-2

“SimulinkUserInterface”onpage2-6

simulink学习,入门指南适合新手,2012b

Simulink®SoftwareBasics

StarttheSimulinkSoftwareInthissection...

“OpentheSimulinkLibraryBrowser”onpage2-2

“CreateaNewSimulinkModel”onpage2-4

“OpenanExistingModel”onpage

2-5

OpentheSimulinkLibraryBrowser

YouneedMATLABrunningbeforeyoucanopentheSimulinkLibraryBrowser.

1StartMATLAB,andthenintheMATLABCommandWindow,entersimulink

TheSimulinkLibraryBrowseropens.

YoucanalsoopentheSimulinkLibraryBrowserfromtheMATLABToolstrip,byclickingtheSimulinkLibrarybutton().

2-2

simulink学习,入门指南适合新手,2012b

StarttheSimulink®Software

IfyouhavenotalreadyloadedSimulink,ashortdelayoccurswhileitloads.TheLibraryBrowseropens.

TokeeptheLibraryBrowseraboveallotherwindowsonyourdesktop,intheLibraryBrowser,selectView>StayonTop.

2-3

本文来源:https://www.bwwdw.com/article/9as4.html

Top