matlab-simulink中文帮助手册
- 格式:pdf
- 大小:5.23 MB
- 文档页数:29
Experiment 1Introduction to Simulink1.1 ObjectiveThe objective of Experiment #1 is to familiarize the students with simulation of power electronic circuits in Matlab/Simulink environment. Please follow the instructions in the laboratory manual.1.2 Simulink Basics TutorialSimulink is a graphical extension to MATLAB for the modeling and simulation of systems. In Simulink, systems are drawn on screen as block diagrams. Many elements of block diagrams are available (such as transfer functions, summing junctions, etc.), as well as virtual input devices (such as function generators) and output devices (such as oscilloscopes). Simulink is integrated with MATLAB and data can be easily transferred between the programs. In this tutorial, we will introduce the basics of using Simulink to model and simulate a system.1.2.1 Starting SimulinkSimulink is started from the MATLAB command prompt by entering the following command: >>simulinkAlternatively, you can click on the "Simulink Library Browser" button at the top of the M ATLAB command window as shown below:The Simulink Library Browser window should now appear on the screen. Most of the blocks needed for modeling basic systems can be found in the subfolders of the main "Simulink" folder (opened by clicking on the "+" in front of "Simulink"). Once the "Simulink" folder has been opened, the Library Browser window should look like:1.2.2 Basic ElementsThere are two major classes of elements in Simulink: blocks and lines. Blocks are used to generate, modify, combine, output, and display signals. Lines are used to transfer signals from one block to another. BlocksThe subfolders underneath the "Simulink" folder indicate the general classes of blocks available for us to use:•Continuous: Linear, continuous-time system elements (integrators, transfer functions, state-space models, etc.)•Discrete: Linear, discrete-time system elements (integrators, transfer functions, state-space models, etc.)•Functions & Tables: User-defined functions and tables for interpolating function values•Math: Mathematical operators (sum, gain, dot product, etc.)•Nonlinear: Nonlinear operators (coulomb/viscous friction, switches, relays, etc.)•Signals & Systems: Blocks for controlling/monitoring signal(s) and for creating subsystems•Sinks: Used to output or display signals (displays, scopes, graphs, etc.)•Sources: Used to generate various signals (step, ramp, sinusoidal, etc.)Blocks have zero to several input terminals and zero to several output terminals. Unused input terminals are indicated by a small open triangle. Unused output terminals are indicated by a small triangular point. The block shown below has an unused input terminal on the left and an unused output terminal on the right.LinesLines transmit signals in the direction indicated by the arrow. Lines must always transmit signals from the output terminal of one block to the input terminal of another block. One exception to this is that a line can tap off of another line. This sends the original signal to each of two (or more) destination blocks, as shown below:Lines can never inject a signal into another line; lines must be combined through the use of a block such as a summing junction.A signal can be either a scalar signal or a vector signal. For Single-Input, Single-Output systems, scalar signals are generally used. For Multi-Input, Multi-Output systems, vector signals are often used, consisting of two or more scalar signals. The lines used to transmit scalar and vector signals are identical. The type of signal carried by a line is determined by the blocks on either end of the line.1.2.3 Building a SystemTo demonstrate how a system is represented using Simulink, we will build the block diagram for a simple model consisting of a sinusoidal input multiplied by a constant gain, which is shown below:This model will consist of three blocks: Sine Wave, Gain, and Scope. The Sine Wave is a Source Block from which a sinusoidal input signal originates. This signal is transferred through a line in the direction indicated by the arrow to the Gain Math Block. The Gain block modifies its input signal (multiplies it by a constant value) and outputs a new signal through a line to the Scope block. The Scope is a Sink Block used to display a signal (much like an oscilloscope).We begin building our system by bringing up a new model window in which to create the block diagram. This is done by clicking on the "New Model" button in the toolbar of the Simulink Library Browser (looks like a blank page).Building the system model is then accomplished through a series of steps:1.The necessary blocks are gathered from the Library Browser and placed in the model window.2.The parameters of the blocks are then modified to correspond with the system we are modeling.3.Finally, the blocks are connected with lines to complete the model.Each of these steps will be explained in detail using our example system. Once a system is built, simulations are run to analyze its behavior.Gathering BlocksEach of the blocks we will use in our example model will be taken from the Simulink Library Browser. To place the Sine Wave block into the model window, follow these steps:1.Click on the "+" in front of "Sources" (this is a subfolder beneath the "Simulink" folder) todisplay the various source blocks available for us to use.2.Scroll down until you see the "Sine Wave" block. Clicking on this will display a shortexplanation of what that block does in the space below the folder list:3. To insert a Sine Wave block into your model window, click on it in the Library Browser and drag the block into your workspace.The same method can be used to place the Gain and Scope blocks in the model window. The "Gain" block can be found in the "Math" subfolder and the "Scope" block is located in the "Sink" subfolder. Arrange the three blocks in the workspace (done by selecting and dragging an individual block to a new location) so that they look similar to the following:Modifying the BlocksSimulink allows us to modify the blocks in our model so that they accurately reflect the characteristics of the system we are analyzing. For example, we can modify the Sine Wave block by double-clicking on it. Doing so will cause the following window to appear:This window allows us to adjust the amplitude, frequency, and phase shift of the sinusoidal input. The "Sample time" value indicates the time interval between successive readings of the signal. Setting this value to 0 indicates the signal is sampled continuously.Let us assume that our system's sinusoidal input has:•Amplitude = 2•Frequency = pi•Phase = pi/2Enter these values into the appropriate fields (leave the "Sample time" set to 0) and click "OK" to accept them and exit the window. Note that the frequency and phase for our system contain 'pi' (3.1415...). These values can be entered into Simulink just as they have been shown.Next, we modify the Gain block by double-clicking on it in the model window. The following window will then appear:Note that Simulink gives a brief explanation of the block's function in the top portion of this window. In the case of the Gain block, the signal input to the block (u) is multiplied by a constant (k) to create the block's output signal (y). Changing the "Gain" parameter in this window changes the value of k.For our system, set k = 5. Enter this value in the "Gain" field, and click "OK" to close the window.The Scope block simply plots its input signal as a function of time, and thus there are no system parameters that we can change for it. We will look at the Scope block in more detail after we have run our simulation.Connecting the BlocksFor a block diagram to accurately reflect the system we are modeling, the Simulink blocks must be properly connected. In our example system, the signal output by the Sine Wave block is transmitted to the Gain block. The Gain block amplifies this signal and outputs its new value to the Scope block, which graphs the signal as a function of time. Thus, we need to draw lines from the output of the Sine Wave block to the input of the Gain block, and from the output of the Gain block to the input of the Scope block.Lines are drawn by dragging the mouse from where a signal starts (output terminal of a block) to where it ends (input terminal of another block). When drawing lines, it is important to make sure that the signal reaches each of its intended terminals. Simulink will turn the mouse pointer into a crosshair when it is close enough to an output terminal to begin drawing a line, and the pointer will change into a double crosshair when it is close enough to snap to an input terminal. A signal is properly connected if its arrowhead is filled in. If the arrowhead is open, it means the signal is not connected to both blocks. To fix an open signal, you can treat the open arrowhead as an output terminal and continue drawing the line to an input terminal in the same manner as explained before.Properly Connected SignalWhen drawing lines, you do not need to worry about the path you follow. The lines will route themselves automatically. Once blocks are connected, they can be repositioned for a neater appearance. This is done by clicking on and dragging each block to its desired location (signals will stay properly connected and will re-route themselves).After drawing in the lines and repositioning the blocks, the example system model should look like:In some models, it will be necessary to branch a signal so that it is transmitted to two or more different input terminals. This is done by first placing the mouse cursor at the location where the signal is to branch. Then, using either the CTRL key in conjunction with the left mouse button or just the right mouse button, drag the new line to its intended destination. This method was used to construct the branch in the Sine Wave output signal shown below:The routing of lines and the location of branches can be changed by dragging them to their desired new position. To delete an incorrectly drawn line, simply click on it to select it, and hit the DELETE key.1.2.4. Running SimulationsNow that our model has been constructed, we are ready to simulate the system. Before starting simulation, we need to set the simulation parameters. To do this, go to the Simulation menu and click on Configuration Parameters. The Configuration Parameters dialog box opens on your desktopEnter desired stop time (e.g. 100 microseconds), and change the Solver Options from Variable-step to fix-step and the step size to 1e-4. The step size specifies the resolution of simulation. Click Apply and OK to close the Configuration Parameters window.Go to the Simulation menu and click on Start, or just click on the "Start/Pause Simulation" button in the model window toolbar (looks like the "Play" button on a VCR). Because our example is a relatively simple model, its simulation runs almost instantaneously. With more complicated systems, however, you will be able to see the progress of the simulation by observing its running time in the lower box of the model window. Double-click the Scope block to view the output of the Gain block for the simulation as a function of time. Once the Scope window appears, click the "Auto scale" button in its toolbar (looks like a pair of binoculars) to scale the graph to better fit the window. Having done this, you should see the following:。
Simulink仿真环境基础学习Simulink是面向框图的仿真软件。
7.1演示一个Simulink的简单程序【例7.1】创建一个正弦信号的仿真模型。
步骤如下:(1) 在MATLAB的命令窗口运行simulink命令,或单击工具栏中的图标,就可以打开Simulink模块库浏览器(Simulink Library Browser) 窗口,如图7.1所示。
(2)单击工具栏上的图标或选择菜单“File ”——“New ”——“Model ”,新建一个名为“untitled ”的空白模型窗口。
(3) 在上图的右侧子模块窗口中,单击“Source ”子模块库前的“+”(或双击Source),或者直接在左侧模块和工具箱栏单击Simulink 下的Source 子模块库,便可看到各种输入源模块。
(4) 用鼠标单击所需要的输入信号源模块“Sine Wave ”(正弦信号),将其拖放到的空白模型窗口“untitled ”,则“Sine Wave ”模块就被添加到untitled 窗口;也可以用鼠标选中“Sine Wave ”模块,单击鼠标右键,在快捷菜单中选择“add to 'untitled'”命令,就可以将“Sine Wave ”模块添加到untitled 窗口,如图7.2所示。
图7.1 Simulink 界面(5) 用同样的方法打开接收模块库“Sinks”,选择其中的“Scope”模块(示波器)拖放到“untitled”窗口中。
(6) 在“untitled”窗口中,用鼠标指向“Sine Wave”右侧的输出端,当光标变为十字符时,按住鼠标拖向“Scope”模块的输入端,松开鼠标按键,就完成了两个模块间的信号线连接,一个简单模型已经建成。
如图7.3所示。
(7) 开始仿真,单击“untitled”模型窗口中“开始仿真”图标,或者选择菜单“Simulink”——“Start”,则仿真开始。
双击“Scope”模块出现示波器显示屏,可以看到黄色的正弦波形。
Simulink 快速入门要构建模型, 可以使用Simulink® Editor 和Library Browser。
启动 MATLAB 软件启动 Simulink 之前, 请先启动MATLAB®。
请参阅启动和关闭(MATLAB)。
配置 MATLAB 以启动 Simulink您在 MATLAB 会话中打开第一个模型时需要的时间比打开后续模型长, 因为默认情况下, MATLAB 会在打开第一个模型时启动 Simulink。
这种即时启动Simulink 的方法可以缩短 MATLAB 启动时间, 避免不必要的系统内存占用。
•要快速打开第一个模型, 您可以配置 MATLAB, 在它启动时同时启动Simulink。
要启动 Simulink 而不打开模型或 Library Browser, 请使用start_simulink。
•根据 MATLAB 的启动方式, 恰当使用此命令:•在 MATLAB startup.m文件中在操作系统命令行中, 使用matlab 命令和-r 开关例如, 要在运行Microsoft®Windows®操作系统的计算机上启动 MATLAB 时启动 Simulink, 请创建具有以下目标的桌面快捷方式:matlabroot\bin\win64\matlab.exe -r start_simulink在 Macintosh 和Linux®计算机上, 可在启动 MATLAB 时使用以下命令启动Simulink 软件:matlab -r start_simulink打开 Simulink Editor•要打开 Simulink Editor, 您可以:•创建一个模型。
在 MATLAB 的Home 选项卡上, 点击Simulink 并选择一个模型模板。
或者, 如果您已经打开了 Library Browser, 请点击New Model 按钮/。
有关创建模型的其他方法, 请参阅创建模型。
使用篇1.以管理员身份运行matlab2.登录后把当前文件夹改成C盘,找到TwinCAT→Functions→TE1400→SetupTwinCATTarget.p3.找到这个文件后右键选择Run,注意:这一步是为了选择matlabsimulink编译的module所需要的编译器种类,是第一次运行使用matlab+TE1400的时候必须执行的,以后就不必每次都操作这一步。
运行后在matlab主窗口提示让你选择是否用本地的编译器因为本地有VS2010的编译器,所以选择y后敲回车随后matlab找到本地有两种编译器,一个是matlab本体的lcc-win32 C2.4.1,另一个是VS2010,选择VS2010所代表的数字,输入2敲回车最后让matlab让你确认编译器的选择,输入y敲回车提示以下信息说明编译器选择完成4.点击工具栏中simulink图标5.弹出simulink编辑界面后,点击工具栏中的打开模型6.找到案例模型TempContrTest.mdl,点击打开7.本次案例模型是一个简单的温度控制External Setpoint是设定温度Feedback Temp是当前温度CoolerON是开关量输出8.打开simulation菜单栏,选择configuration parameters进行参数设定(1)进入参数设定后,选择右边的树形栏中的Solver,把其中的Type改成Fixed-step(2)之后选择树形栏中的Code Generation,把其中的System target file改成TwinCAT.tlc 点击Browse可以进行选择(3)继续选择树形栏中的Tc Module,在Publish module和Publish binaries for platform “TwinCAT RealTime(x86)”前打勾(4)最后选择树形栏中的Tc Advanced,把Task assignment改成Default在Add to cyclic caller,Variable cycle time,Export block digram以及Export block diagram debug information前打勾(5)以上操作完成后点击左下角的Apply(6)选择树形栏中的Code Generation,把Generate code only勾选后点击Generate code,随后matlab就开始把这个模型通过TE1400生成TC3所识别的Module了(7)回到matlab主窗口,等看到以下提示说明Module生成完成(8)我们来看下生成的Module会在什么位置可以发现在TwinCAT/3.1/CustomConfig/Modules路径下会生成名字和案例模型名字一样的文件夹TempContrTest打开可以发现里面其实主要是.tmc文件是TC3所需要的,其他都是一些描述文件,所以可以把.tmc文件拷贝出来,给一些没有Matlab的电脑上用9.打开TC3,并新建项目10.把名称改成英文,例如matlabsimulink,点击确认11.打开SYSTEM,右键TcCOM Objects添加新项12.TC3会自动找到之前生成的.tmc文件,选中后点击OK进行添加13.添加好后我们可以发现TcCOM Objects下出现matlab生成的Module,并且3个变量出现在IO位置,方便和PLC程序或者硬件IO进行变量连接14.右键Tasks添加新项名字可以改成matlab,点击OK添加新的Task15.因为我需要实施做温度计算,所以可以这个Task的优先级提高,修改成1,周期用默认的10ms即可16.双击TcCOM Objects下面的Object1(TempContrTest)Depend On改成Manual Config,并把Task分配成之前创建的名为“matlab”的Task17.右键PLC添加新项18.把名称修改为英文,例如test19.编辑一段模拟程序,模拟温度的升降20.程序写好后右键test Project,选择生成开始编译程序21.编译好后在test Instance自动生成3个变量22.接下来要做的就是把PLC中3个变量和matlab中三个变量链接起来Switch→CoolerONSP→External SetpointPV Feedback Temp23.变量链接完成后开始下传配置和程序,选择菜单栏TwinCAT,点击Activate Configuration弹出窗口点击确定提示切换到运行模式点击确定观察右下角图标是否编程绿色运行状态弹出窗口点击确定提示切换到运行模式点击确定观察右下角图标是否编程绿色运行状态24.打开PLC菜单,选择“登录到”把程序在线25.打开PLC菜单,选择“启动”把程序运行26.观察程序,看到成功利用matlab温度算法运行程序27.打开Object1(TempContrTest),选择Block Diagram也可以同时观察Matlab温度算法实时状态注:上图中可以看到由一个红色字提示说是非商业的,虽然TE1400插件装上了,但用的还是7天试用版,所以对于试用版有一些限制,查询information system可以看到如下:TC3中Scope View简单使用在之前的基础上来看下TC3下Scope View如何使用,装好TC3后Scope View会自动集成在TC3中1.首先右键“解决方案”选择添加,点击新建项目2.选择TwinCAT Measurement中的Measurement Scope Project,名称改成英文,例如tempcontrol,点击确定3.右键Axis,选择Target Browser4.打开小电脑图标下的Port_851(851),点击MAIN5.把MAIN程序中PV和SP分别添加到同一个坐标上6.保证程序在运行后,点击工具栏中的Record开始记录两个变量7.随后就可以观察到当前PV和SP的示波图下图中绿色是PV,蓝色是SP。
第1章MATLAB 6.5环境1.1MATLAB简介●MATLAB(Matrix Laborator)是MathWorks公司开发科学与工程计算软件;●广泛应用于自动控制、数学运算、信号分析、计算机技术、图像信号处理、财务分析、航天工业、汽车工业、生物医学工程、语音处理和雷达工程等行业;●国内外高校和研究部门科学研究的重要工具;●MATLIB 已成为数学计算工具方面事实上的标准,MATLIB 6.5是最新版本。
1.1.1 MATLAB工具箱●MATLAB由基本部分和功能各异的工具箱组成。
基本部分是MATLAB的核心,工具箱是扩展部分。
●工具箱是用MATLAB的基本语句编成的各种子程序集,用于解决某一方面的专门问题或实现某一类的新算法。
●MATLAB有以下主要的工具箱:▪控制系统工具箱(Control System Toolbox)▪系统辨识工具箱(System Identification Toolbox)▪信号处理工具箱(Signal Processing Toolbox)▪神经网络工具箱(Neural Network Toolbox)▪模糊逻辑控制工具箱(Fuzzy Logic Toolbox)▪小波工具箱(Wavelet Toolbox)▪模型预测控制工具箱(Model Predictive Control Toolbox)▪通信工具箱(Communication Toolbox)▪图像处理工具箱(Image Processing Toolbox)▪频域系统辨识工具箱(Frequency System Identification Toolbox)▪优化工具箱(Optimization Toolbox)▪偏微分方程工具箱(Partial Differential Equation Toolbox)▪财政金融工具箱(Financial Toolbox)▪统计工具箱(Statistics Toolbox)1.1.2 MATLAB功能和特点1.功能强大(1) 运算功能强大●MATLAB的数值运算要素不是单个数据,而是矩阵,每个元素都可看作复数,运算包括加、减、乘、除、函数运算等;●通过MATLAB的符号工具箱,可以解决在数学、应用科学和工程计算领域中常常遇到的符号计算问题。
使用篇1.以管理员身份运行matlab2.登录后把当前文件夹改成C盘,找到TwinCAT→Functions→TE1400→SetupTwinCATTarget.p3.找到这个文件后右键选择Run,注意:这一步是为了选择matlabsimulink编译的module所需要的编译器种类,是第一次运行使用matlab+TE1400的时候必须执行的,以后就不必每次都操作这一步。
运行后在matlab主窗口提示让你选择是否用本地的编译器因为本地有VS2010的编译器,所以选择y后敲回车随后matlab找到本地有两种编译器,一个是matlab本体的lcc-win32 C2.4.1,另一个是VS2010,选择VS2010所代表的数字,输入2敲回车最后让matlab让你确认编译器的选择,输入y敲回车提示以下信息说明编译器选择完成4.点击工具栏中simulink图标5.弹出simulink编辑界面后,点击工具栏中的打开模型6.找到案例模型TempContrTest.mdl,点击打开7.本次案例模型是一个简单的温度控制External Setpoint是设定温度Feedback Temp是当前温度CoolerON是开关量输出8.打开simulation菜单栏,选择configuration parameters进行参数设定(1)进入参数设定后,选择右边的树形栏中的Solver,把其中的Type改成Fixed-step(2)之后选择树形栏中的Code Generation,把其中的System target file改成TwinCAT.tlc 点击Browse可以进行选择(3)继续选择树形栏中的Tc Module,在Publish module和Publish binaries for platform “TwinCAT RealTime(x86)”前打勾(4)最后选择树形栏中的Tc Advanced,把Task assignment改成Default在Add to cyclic caller,Variable cycle time,Export block digram以及Export block diagram debug information前打勾(5)以上操作完成后点击左下角的Apply(6)选择树形栏中的Code Generation,把Generate code only勾选后点击Generate code,随后matlab就开始把这个模型通过TE1400生成TC3所识别的Module了(7)回到matlab主窗口,等看到以下提示说明Module生成完成(8)我们来看下生成的Module会在什么位置可以发现在TwinCAT/3.1/CustomConfig/Modules路径下会生成名字和案例模型名字一样的文件夹TempContrTest打开可以发现里面其实主要是.tmc文件是TC3所需要的,其他都是一些描述文件,所以可以把.tmc文件拷贝出来,给一些没有Matlab的电脑上用9.打开TC3,并新建项目10.把名称改成英文,例如matlabsimulink,点击确认11.打开SYSTEM,右键TcCOM Objects添加新项12.TC3会自动找到之前生成的.tmc文件,选中后点击OK进行添加13.添加好后我们可以发现TcCOM Objects下出现matlab生成的Module,并且3个变量出现在IO位置,方便和PLC程序或者硬件IO进行变量连接14.右键Tasks添加新项名字可以改成matlab,点击OK添加新的Task15.因为我需要实施做温度计算,所以可以这个Task的优先级提高,修改成1,周期用默认的10ms即可16.双击TcCOM Objects下面的Object1(TempContrTest)Depend On改成Manual Config,并把Task分配成之前创建的名为“matlab”的Task17.右键PLC添加新项18.把名称修改为英文,例如test19.编辑一段模拟程序,模拟温度的升降20.程序写好后右键test Project,选择生成开始编译程序21.编译好后在test Instance自动生成3个变量22.接下来要做的就是把PLC中3个变量和matlab中三个变量链接起来Switch→CoolerONSP→External SetpointPV Feedback Temp23.变量链接完成后开始下传配置和程序,选择菜单栏TwinCAT,点击Activate Configuration弹出窗口点击确定提示切换到运行模式点击确定观察右下角图标是否编程绿色运行状态弹出窗口点击确定提示切换到运行模式点击确定观察右下角图标是否编程绿色运行状态24.打开PLC菜单,选择“登录到”把程序在线25.打开PLC菜单,选择“启动”把程序运行26.观察程序,看到成功利用matlab温度算法运行程序27.打开Object1(TempContrTest),选择Block Diagram也可以同时观察Matlab温度算法实时状态注:上图中可以看到由一个红色字提示说是非商业的,虽然TE1400插件装上了,但用的还是7天试用版,所以对于试用版有一些限制,查询information system可以看到如下:TC3中Scope View简单使用在之前的基础上来看下TC3下Scope View如何使用,装好TC3后Scope View会自动集成在TC3中1.首先右键“解决方案”选择添加,点击新建项目2.选择TwinCAT Measurement中的Measurement Scope Project,名称改成英文,例如tempcontrol,点击确定3.右键Axis,选择Target Browser4.打开小电脑图标下的Port_851(851),点击MAIN5.把MAIN程序中PV和SP分别添加到同一个坐标上6.保证程序在运行后,点击工具栏中的Record开始记录两个变量7.随后就可以观察到当前PV和SP的示波图下图中绿色是PV,蓝色是SP。
教育部重点实验室软件操作手册之Matlab Simulink用户手册合肥工业大学管理学院2010-10-22目录1 简介 (4)1.1 产品概述 (4)1.1.1 概述 (4)1.1.2 基于模型的设计工具 (4)1.1.3 仿真工具 (5)1.1.4 分析工具 (5)1.1.5 Simulink软件是如何和matlab环境交互的 (5)1.2 什么是基于模型的设计 (6)1.2.1 以模型为基础的设计 (6)1.2.2 建模过程 (6)1.3 相关产品 (7)2 Simulink软件基本知识 (8)2.1 启动Simulink软件 (8)2.1.1 打开Simulink模块库浏览器 (8)2.1.2 打开一个模型 (9)2.2 Simulink使用者接口 (11)2.2.1 Simulink模块库浏览器 (11)2.2.2 Simulink模型窗口 (13)2.3 从Simulink软件中寻找帮助 (13)2.3.1 Simulink在线帮助 (13)2.3.2 Simulink演示模型 (14)2.3.3 网站资源 (15)3 创建一个Simulink模型 (15)3.1 概述 (15)3.2 创建一个简单的模型 (16)3.2.1 概述 (16)3.2.2 创建一个新模型 (16)3.2.3 在你的模型中增加模块 (17)3.2.4 从模型窗口中移动模块 (18)3.2.6 保存模型 (21)3.3 仿真这个模型 (21)3.3.1 概述 (21)3.3.2 设置仿真选项 (22)3.3.3 运行仿真然后观察结果 (22)4 建立一个动态控制系统的模型 (23)4.1 概述 (23)4.2 理解演示模型 (24)4.2.1 打开演示模型 (24)4.2.2 剖析演示模型 (24)4.2.3 使用子系统 (25)4.2.4 封装子系统 (27)4.3 仿真这个模型 (28)4.3.1 运行仿真 (28)4.3.2 修改仿真参数 (29)4.3.3 从matlab工作窗口中输入数据 (33)4.3.4 输出数据到matlab工作区 (36)1 简介1.1 产品概述1.1.1 概述Simulink软件可以建模,仿真和分析动态系统。
精品Simulink中文帮助Simulink可以对实际的动态系统建模,仿真并实时分析系统输出的变化。
利用Simulink仿真动态系统分两步:1,用户创建一个结构框图,利用Simulink模型编辑器,通过系统的输入,传递函数,输出描述数学关系2,仿真系统的模型,并指定开始时间和结束时间二、Simulink动态系统建模仿真结构图是动态系统数学模型的图形化描述,数学模型由一组方程组表示,包括比例,微分,微分方程。
创建动态系统模型的要素用户可以用Simulink软件包建模、仿真和分析模型输出随时间而改变的系统,这样的系统通常是指动态系统:利用Simulink,用户可以搭建很多领域的动态系统,包括电子电路、减振器、刹车系统和许多其他的电子、机械和热力学系统。
使用Simulink仿真动态系统包括两个过程。
首先,利用Simulink的模型编辑器创建被仿真系统的模型方块图,系统模型描述了系统中输入、输出、状态和时间的数学关系,然后使用Simulink根据用户输入的模型信息在一个时间段内仿真动态系统。
本节综合给出了用户在Simulink中创建动态系统模型时需要理解和掌握的所有建模要素。
1方块图Simulink方块图是动态系统数学模型的图形化描述,动态系统的数学模型是由一组方程来表示的,而由方块图模型所描述的数学方程就是众所周知的代数方程、微分方程和(或)差分方程。
方块图模型中的每个模块都属于一个特定的Simulink模块类型,模块的类型决定了模块的输出、输入、状态与时间的关系,在建立系统模型图时,Simulink方块图中可以包含任意数目、任意类型的模块,Simulink中的模块包括非虚拟模块和虚拟模块。
非虚拟模块是基本系统,虚拟模块则是为了模型方块图组织结构的简化而建立的,它在模型方块图所描述的系统方程定义中不起任何作用、如BuCreator模块和BuSelector模块就是虚拟模块,它们的作用只是把信号\捆绑\在一起用来简化方块图,而且也增加了模型的可读性。
MATLAB/SIMULINK的操作指导一SIMULINK简介Simulink是MATLAB下的一个软件包,是一个结合了框图界面和交互仿真能力的系统级设计和仿真工具。
它以MATLAB的核心数学、图形和语言为基础,可以让用户毫不费力地完成从算法开发、仿真或者模型验证的全过程,而不需要传递数据、重写代码或改变软件环境。
Simulink是基于MATLAB的图形化仿真环境。
它使用图形化的系统模块对动态系统进行描述,并在此基础上进行动态系统的求解。
利用Simulink对动态系统进行仿真的核心在于,MATLAB计算引擎对系统微分方程核差分方程求解。
Simulink与MATLAB时高度集成在一起的,因此,Simulink与MATLAB之间可以灵活的交互操作。
1 Simulink的窗体介绍由于Simulink是基于MATLAB环境之上的高性能的系统及仿真平台。
因此,启动Simulink 之前必须首先运行MATLAB,然后,才能启动Simulink并建立系统的仿真模型。
MATLAB成功启动后,在Command Window窗口的工作区中,键入simulink后,回车即可启动Simulink,或点击MATLAB窗体上的Simulink的快捷键也可启动Simulink,操作如图1所示。
启动后的Simulink窗体以及功能介绍如图2所示。
图1 两种启动Simulink方法的图示说明图.2 Simulink库浏览器窗口2 一个MATLAB/Simulink库自代的演示实例MATLAB/Simulink自代了大量的演示实例,为读者创建模型提供许多有益的帮助,读者可借鉴这些实例。
浏览演示实例可在Command Window窗的工作区键入demo回车即可,或点击MATLAB窗体的左下角的Start按钮也可浏览,选择出所需的模型。
线性电路的暂态分析模型如图3所示,其运行结果如图.4所示。
图 3 线性电路暂态分析的演示仿真模型图.4 线性电路暂态分析的演示仿真模型的运行结果3 创建一个MATLAB实例对Simulink库有了初步了解后,创建一个简单电路的仿真模型并运行。