Matlab, Simulink - Simulink Modeling Tutorial - Train System
- 格式:pdf
- 大小:1.15 MB
- 文档页数:14
matlab simulink设计与建模-概述说明以及解释1.引言1.1 概述概述部分的内容可以描述该篇文章的主题和内容的重要性。
可以参考以下写法:引言部分首先概述了文章的主要内容和结构,主要涉及Matlab Simulink的设计与建模方法。
接下来,我们将详细介绍Matlab Simulink 的基本概念、功能和应用,并探讨其在系统设计和仿真建模中的重要性。
本文旨在向读者提供一种全面了解Matlab Simulink的方法,并帮助他们在实际工程项目中运用该工具进行系统设计和模拟。
通过本文的阅读,读者将能够深入了解Matlab Simulink的优势和特点,并学会如何使用其开发和设计各种复杂系统,从而提高工程的效率和准确性。
在接下来的章节中,我们将重点介绍Matlab Simulink的基本概念和设计方法,以及实际案例的应用。
最后,我们将通过总结现有的知识和对未来发展的展望,为读者提供一个全面的Matlab Simulink设计与建模的综合性指南。
1.2文章结构1.2 文章结构本文将以以下几个部分展开对MATLAB Simulink的设计与建模的讨论。
第一部分是引言部分,其中概述了本文的主要内容和目的,并介绍了文章的结构安排。
第二部分是正文部分,主要包括MATLAB Simulink的简介和设计与建模方法。
在MATLAB Simulink简介部分,将介绍该软件的基本概念和功能特点,以及其在系统设计和建模中的优势。
在设计与建模方法部分,将深入讨论MATLAB Simulink的具体应用技巧和方法,包括系统建模、模块化设计、信号流图、仿真等方面的内容。
第三部分是结论部分,主要总结了本文对MATLAB Simulink设计与建模的讨论和分析,并对其未来的发展方向进行了展望。
通过以上结构安排,本文将全面介绍MATLAB Simulink的设计与建模方法,以期为读者提供一个全面而系统的了解,并为相关领域的研究和应用提供一些借鉴和参考。
matlabsimulink教程Matlab Simulink是一种基于Matlab的高级系统建模和仿真工具。
它允许用户通过图形化界面来构建和模拟复杂的多域系统。
首先,我们来介绍如何启动Simulink。
在Matlab主界面的命令窗口中输入simulink即可打开Simulink图形界面。
Simulink界面主要由工具栏、模型窗口和浏览器窗口组成。
工具栏上的各种按钮可以帮助用户进行模型的构建和仿真。
模型窗口用于进行模型的可视化编辑,用户可以从浏览器中选择模型中的各个组件进行添加和连接。
在开始使用Simulink之前,我们建议用户先了解一些基本概念和术语。
Simulink中的基本组成单位是模块,模块可以是输入、输出、运算器、信号转换器等。
这些模块可以通过连线连接起来,形成一个完整的系统模型。
模块间的信号传递可以是连续的、离散的或者混合的。
在Simulink中,用户可以通过选择不同的模块和参数来构建自己需要的系统模型。
Simulink有很多强大的功能,其中之一是仿真功能。
用户可以设置各种参数来对系统模型进行仿真,比如时间步长、仿真时长等。
Simulink会根据用户设定的参数对系统模型进行仿真,并产生仿真结果。
用户可以通过可视化界面查看仿真结果,也可以将仿真结果保存为数据文件和图形文件。
另外,Simulink还提供了各种调试工具和分析工具,帮助用户对系统模型进行诊断和优化。
除了系统建模和仿真功能,Simulink还可以与其他Matlab工具和工具箱进行集成。
用户可以在Simulink中调用Matlab函数和脚本,也可以使用不同的工具箱来扩展Simulink的功能。
Simulink还支持与外部硬件的连接和通信,比如数据采集卡、控制器等。
总之,Matlab Simulink是一个功能强大、易于使用的系统建模和仿真工具。
通过Simulink,用户可以通过图形化界面来构建和仿真复杂的系统模型,同时还可以进行调试和优化。
matlab simulink模型搭建方法Matlab Simulink是一个强大的多领域仿真和模型搭建环境,广泛应用于控制系统、信号处理、通信系统等多个领域。
本文将详细介绍Matlab Simulink模型搭建的方法,帮助您快速掌握这一技能。
一、Simulink基础操作1.启动Simulink:在Matlab命令窗口输入“simulink”,然后按回车键,即可启动Simulink。
2.创建新模型:在Simulink开始页面,点击“新建模型”按钮,或在菜单栏中选择“文件”→“新建”→“模型”,创建一个空白模型。
3.添加模块:在Simulink库浏览器中,找到所需的模块,将其拖拽到模型窗口中。
4.连接模块:将鼠标光标放在一个模块的输出端口上,按住鼠标左键并拖拽到另一个模块的输入端口,松开鼠标左键,完成模块间的连接。
5.参数设置:双击模型窗口中的模块,可以设置模块的参数。
6.模型仿真:在模型窗口中,点击工具栏上的“开始仿真”按钮,或选择“仿真”→“开始仿真”进行模型仿真。
二、常见模块介绍1.源模块:用于生成信号,如Step、Ramp、Sine Wave等。
2.转换模块:用于信号转换和处理,如Gain、Sum、Product、Scope 等。
3.控制模块:用于实现控制算法,如PID Controller、State-Space等。
4.建模模块:用于构建物理系统的数学模型,如Transfer Fcn、State-Space等。
5.仿真模块:用于设置仿真参数,如Stop Time、Solver Options等。
三、模型搭建实例以下以一个简单的线性系统为例,介绍Simulink模型搭建过程。
1.打开Simulink,创建一个空白模型。
2.在库浏览器中找到以下模块,并将其添加到模型窗口中:- Sine Wave(正弦波信号源)- Transfer Fcn(传递函数模块)- Scope(示波器模块)3.连接模块:- 将Sine Wave的输出端口连接到Transfer Fcn的输入端口。
Simulink仿真环境基础学习Simulink是面向框图的仿真软件。
7.1演示一个Simulink的简单程序【例7.1】创建一个正弦信号的仿真模型。
步骤如下:(1) 在MATLAB的命令窗口运行simulink命令,或单击工具栏中的图标,就可以打开Simulink模块库浏览器(Simulink Library Browser) 窗口,如图7.1所示。
图7.1 Simulink界面(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所示。
(5) 用同样的方法打开接收模块库“Sinks”,选择其中的“Scope”模块(示波器)拖放到“untitled”窗口中。
(6) 在“untitled”窗口中,用鼠标指向“Sine Wave”右侧的输出端,当光标变为十字符时,按住鼠标拖向“Scope”模块的输入端,松开鼠标按键,就完成了两个模块间的信号线连接,一个简单模型已经建成。
如图7.3所示。
(7) 开始仿真,单击“untitled”模型窗口中“开始仿真”图标,或者选择菜单“Simulink”——“Start”,则仿真开始。
双击“Scope”模块出现示波器显示屏,可以看到黄色的正弦波形。
matlab simulink 环节(实用版)目录1.MATLAB Simulink 简介2.MATLAB Simulink 的基本组成3.MATLAB Simulink 的环节类型4.如何创建和编辑 MATLAB Simulink 环节5.MATLAB Simulink 环节的应用实例正文一、MATLAB Simulink 简介MATLAB Simulink 是 MATLAB 的一种可视化仿真环境,用户可以在其中建立、仿真和分析动态系统模型。
Simulink 提供了一个基于图形的用户界面,用户可以在其中通过拖拽和连接各个环节来构建模型。
Simulink 适用于各种领域的动态系统建模,如控制、通信、信号处理等。
二、MATLAB Simulink 的基本组成MATLAB Simulink 的基本组成包括以下几个部分:1.模型编辑器:模型编辑器是 Simulink 的主要工作区域,用户可以在其中创建和编辑模型。
2.库:库中包含了各种用于构建模型的预定义环节。
库分为 Simulink 标准库和自定义库两类。
3.工具栏:工具栏提供了一系列常用操作的快捷方式,如创建新模型、打开库等。
4.命令窗口:命令窗口用于执行 MATLAB 命令和 Simulink 操作,如仿真、求解等。
三、MATLAB Simulink 的环节类型MATLAB Simulink 中的环节分为以下几类:1.连续环节:表示连续时间系统,如积分器、微分器等。
2.离散环节:表示离散时间系统,如采样器、保持器等。
3.函数环节:表示各种数学函数,如线性函数、非线性函数等。
4.逻辑环节:表示逻辑运算,如与门、或门、非门等。
5.信号发生器:表示信号生成器,如正弦波发生器、脉冲发生器等。
6.接收器:表示信号接收器,如显示、记录等。
四、如何创建和编辑 MATLAB Simulink 环节在 MATLAB Simulink 中创建和编辑环节的方法如下:1.从库中选择环节:打开库,找到所需环节,单击并拖拽到模型编辑器中。
Train systemFree body diagram and Newton's lawModel ConstructionRunning the ModelObtaining M ATLAB ModelIn Simulink, it is very straightforward to represent a physical system or a model. In general, a dynamic system can be constructed from just basic physical laws. We will demonstrate through an example.Train systemIn this example, we will consider a toy train consisting of an engine and a car. Assuming that the train only travels in one direction, we want to apply control to the train so that it has a smooth start-up and stop, along with a constant-speed ride.The mass of the engine and the car will be represented by M1 and M2, respectively. The two are held together by a spring, which has the stiffness coefficient of k. F represents the force applied by the engine, and the Greek letter, mu (which will also be represented by the letter u),represents the coefficient of rolling friction.The system can be represented by following Free Body Diagrams.Page 1From Newton's law, you know that the sum of forces acting on a mass equals the mass times its acceleration. In this case, the forces acting on M1 are the spring, the friction and the force applied by the engine. The forces acting on M2 are the spring and the friction. In the vertical direction, the gravitational force is canceled by the normal force applied by the ground, so that there will be no acceleration in the vertical direction. We will begin to construct the model simply from the expressions:Sum(forces_on_M1)=M1*x1''Sum(forces_on_M1)=M1*x1''Constructing The ModelThis set of system equations can now be represented graphically, without further manipulation. First, we will construct two copies (one for each mass) of the expressions sum_F=Ma ora=1/M*sum_F. Open a new model window, and drag two Sum blocks (from the Linear library), one above the other. Label these Sum blocks "Sum_F1" and "Sum_F2".The outputs of each of these Sum blocks represents the sum of the forces acting on each mass. Multiplying by 1/M will give us the acceleration. Drag two Gain blocks into your model and attach each one with a line to the outputs of the Sum blocks.Page 2attach each one with a line to the outputs of the Sum blocks.These Gain blocks should contain 1/M for each of the masses. We will be taking these variab as M1 and M2 from the M ATLAB environment, so we can just enter the variab in the Gain blocks. Double-click on the upper Gain block and enter the following into the Gain field.1/M1Similarly, change the second Gain block to the following.1/M2Now, you will notice that the gains did not appear in the Gain blocks, and just "-K-" shows up. This is because the blocks are two small on the screen to show 1/M2 inside the triangle. The blocks can be resized so that the actual gain can be seen. To resize a block, select it by clicking on it once. Small squares will appear at the corners. Drag one of these squares to stretch the block.Page 3signal line output from the Sum blocks. Also, label these two Gain blocks "a1" and "a2".The outputs of these gain blocks are the accelerations of each of the masses. We are interested in both the velocities and the positions of the masses. Since velocity is the integral of acceleration, and position is the integral of velocity, we can generate these signals using integrator blocks. Drag two integrator blocks into your model for each of the two accelerations. Connect them with lines in two chains as shown below. Label these integrators "v1", "x1", "v2", and "x2" since these are the signals these integrators will generate.Page 4of these integrators. Label them "View_x1" and "View_x2".Now we are ready to add in the forces acting on each mass. First, you need to adjust the inputs on each Sum block to represent the proper number (we will worry about the sign later) of forces. There are a total of 3 forces acting on M1, so change the Sum_F1 block's dialog box entry to:+++There are only 2 forces acting on M2, so we can leave Sum_F1 alone for now.Page 5The first force acting on M1 is just the input force, F. Drag a Signal Generator block from the Sources library and connect it to the uppermost input of the Sum_F1 block. Label the SignalGenerator "F".The next force acting on M1 is the friction force. This force is equal to:F_friction_1=mu*g*M1*v1To generate this force, we can tap off the velocity signal and multiply by a gain, mu*g*M1.Drag a Gain block into your model window. Tap off the line coming from the v1 integrator and connect it to the input of the Gain block (draw this line in several steps if necessary). Connect the output of the Gain block to the second input of Sum_F1. Change the gain of thisPage 6Connect the output of the Gain block to the second input of Sum_F1. Change the gain of this gain block to the following.mu*g*M1Resize the Gain block to display the gain and label the gain block Friction_1.This force, however, acts in the negative x1-direction. Therefore, it must come into theSum_F1 block with negative sign. Change the list of signs of Sum_F1 to+-+The last force acting on M1 is the spring force between masses. This is equal to:Page 7The last force acting on M1 is the spring force between masses. This is equal to:k*(x1-x2)First, we need to generate (x1-x2) which we can then multiply by k to generate the force. Drag a Sum block below the rest of your model. Label it "(x1-x2)" and change its list of signs to-+Since this summation comes from right to left, we need to flip the block around. Select the bloc by single-clicking on it and select Flip from the Format menu (or hit Ctrl-F). You should see the following.Now, tap off the x2 signal and connect it to the negative input of the (x1-x2) Sum block. Tap off the x1 signal and connect it to the positive input. This will cause the lines to cross. Lines may cross, but they are only actually connected where a small block appears (such as at a tap point).Page 8Now, we can multiply this position difference by the spring constant to generate the spring force. Drag a Gain block into your model to the left of the Sum blocks. Change it's value to k and label it "spring". Connect the output of the (x1-x2) block to the input of the spring block, and the output of the spring block to the third input of Sum_F1. Change the third sign ofSum_F1 to negative (use +--).Now, we can apply forces to M2. For the first force, we will use the same spring force we just generated, except that it adds in with positive sign. Simply tap off the output of the spring block and connect it to the first input of Sum_F2.Page 9The last force to add in the the friction on M2. This is done in the exact same manner as the friction on M1, tapping off v2, multiplying by a gain of mu*g*M2 and adding to Sum_F2with negative sign. After constructing this, you should have the following.Now the model is complete. We simply need to supply the proper input and view the proper output. The input of the system will be the force, F, provided by the engine. We already have placed the function generator at the input. The output of the system will be the velocity of the engine. Drag a Scope block from the Sinks block library into your model. Tap a line off the output of the "v1" integrator block to view the output. Label the scope "View_v1".Page 10Now, the model is complete. Save your model in any file you like. You can download the completed model here.Running the ModelBefore running the model, we need to assign numerical values to each of the variab used in the model. For the train system, letM1 = 1 kgM2 = 0.5 kgk = 1 N/secF= 1 Nu = 0.002 sec/mg = 9.8 m/s^2Create an new m-file and enter the following commands.M1=1;M2=0.5;k=1;F=1;mu=0.002;g=9.8;Execute your m-file to define these values. Simulink will recognize M ATLAB variab for use in the model.Page 11the model.Now, we need to give an appropriate input to the engine. Double-click on the function generator (F block). Select a square wave with frequency .001Hz and amplitude -1 (positive amplitude steps negative before stepping positive).The last step before running the simulation is to select an appropriate simulation time. To view one cycle of the .001Hz square wave, we should simulate for 1000 seconds. Select Parameters from the Simulation menu and change the Stop Time field to 1000. Close the dialog box.Now, run the simulation and open the View_v1 scope to examine the velocity output (hit autoscale). The input was a square wave with two steps, one positive and one negative. Physically, this means the engine first went forward, then in reverse. The velocity output reflects this.Page 12Obtaining M ATLAB ModelWe can now extract a M ATLAB model (state-space or transfer function) from out simulink model. In order to do this, delete the View_v1 scope and put an Out Block (from the Connections library) in its place. Also, delete the F function generator block and put an In Block (from the Connections library) in its place. The in and out blocks define the input and output of the system we would like to extract. For a detailed description of this process and other ways of integrating M ATLAB with Simulink, click here.Save this model as train2.mdl or download our version here. Now, we can extract the model into M ATLAB. Enter the following command at the M ATLAB command window to extract a state-space model.[A,B,C,D]=linmod('train2')You should see the following output which shows a state-space model of your Simulink model.A =-0.0196 0 1.0000 -1.00000 -0.0196 -2.0000 2.00000 1.0000 0 01.0000 0 0 0B =1Page 13C =1 0 0 0D =To obtain a transfer function model, enter the following command at the M ATLAB command prompt.[num,den]=ss2tf(A,B,C,D)You will see the following output representing the transfer function of the train system.num =0 1.0000 0.0196 2.0000 0.0000den =1.0000 0.0392 3.0004 0.0588 0.0000These models are equivalent (although the states are in different order) to the model obtained by hand in the M ATLAB tutorials.Simulink ExamplesCruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Ball and BeamTutorialsM ATLAB Basics | M ATLAB Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Simulink Basics | Simulink Modeling | ExamplesPage 14。