MATLAB Simulink – Starting Simulink

MATLAB Simulink – Starting Simulink ”; Previous Next In this chapter, we will understand about using Simulink to build models. Here is a MATLAB display − You can start Simulink by using simulink command in the MATLAB command window as shown below − Click on enter to open the Simulink startup page as shown below − You can also open Simulink from MATLAB interface directly by clicking on Simulink icon as shown below − When you click on the Simulink icon, it will take you to a Simulink startup page, as shown below − The startup page has a blank model, subsystem, library to start the model from scratch. There are also some built-in templates that can help the users to start with. To create a model, the user can click on blank model and it will display a page as shown below − Click on Save to save your model. The blocks to build your model are available inside the Simulink library browser. Click on library browser as shown below − The library browser has a list of all types of libraries with different blocks as shown below − Libraries in Simulink Let us understand some of the commonly used libraries in Simulink. Continuous A continuous blocks library gives you blocks related to derivatives and integrations. The list of blocks are as follows − Dashboard With Dashboard, you will get controls and indicator blocks that help to interact with simulations. The following screen will appear on your computer − Discontinuities Here, you will get a list of discontinuous functions blocks as displayed below − Discrete Here, you will get time relation function blocks as shown below − Logic and Bit Operations In this category, you will get all logical and relational type blocks as displayed below − Lookup Tables You will all the sine, cosine function blocks as shown below − Math Operations All mathematical operations like Add, Absolute, divide, subtract are available. The list is as follows − Messages and Events This block has all the message/communication related functions as shown below − Model Verification The blocks present here helps to self-verify models, such as Check Input Resolution. The following screen will appear on your computer − Model-Wide Utilities This gives you blocks like Model info, Block Support Table etc. The following screen will appear on your computer − Ports and Subsystems You will get blocks like a subsystem, switch case, enable etc. The list is displayed below − Signal Attributes Modify the signal attribute blocks such as Data Type Conversion. The following screen will appear on your computer − Signal Routing The blocks in this category is used to route signal blocks such as bus creator, switch etc.The following screen will appear on your computer − Sinks The blocks in this category help to display or export signal data blocks such as Scope andTo Workspace. The following screen will appear on your computer − Sources It helps to generate or import data blocks. For example, sine wave. The following screen will appear on your computer − String This category has string related blocks as shown below − User Defined functions Custom function blocks such as MATLAB Function, MATLAB System, Simulink Function, and Initialize Function. The following screen will appear on your computer − Print Page Previous Next Advertisements ”;

MATLAB Simulink – Logic Gates Model

MATLAB Simulink – Logic Gates Model ”; Previous Next In this chapter, let us understand how to build a model that demonstrates the logic gates. For example, gates like OR, AND, XOR etc. Open the Simulink and open a blank model as shown below − Click on blank model and select the Simulink library as shown below − Let us select the block that we want to build a OR gate. We need two constant blocks to act as inputs, a logic operator block and a display block. The constant and logic operator block will get from commonly used blocks library. Select the blocks and drag in your model or just type the name of the block in your model and select the block as shown below − Select the constant block, we need two constant block, a logical operator and a constant. The blocks will look as shown below − Right click on the logic operator block and it will display the block parameters as shown below − With logical operator you can use AND, OR, NAND, NOR, XOR, NXOR and NOT gates. Right now we are going to select the OR gate. Now connect the lines and the model will be as shown below − For an OR gate if the inputs are 1,1 the output will be 1. If the inputs are 0,0 the output will be 0. Right now, the constant has values 1,1. Let us run the model to see the output as shown below − We can see in the display block the output shown is 1. Let us now change the constant value to 0. Right click on constant block and change the value as shown below − After changing the values of constant to 0, the output will become 0 when you run the model. The output is as shown below − Let us now change the constant values to 0,1 and see the output − With values as 1,0, the display will be as follows − Similarly, you can design the AND and other gates. Print Page Previous Next Advertisements ”;

MATLAB Simulink – Lines

MATLAB Simulink – Lines ”; Previous Next In the previous chapter, we learnt about the different types of blocks which are available with Simulink library. In this chapter, we are going to understand about lines. Lines are used to connect the blocks with an arrow. Each block will have its own input and output connector. The communication between the blocks will take place with the help of lines. Let us understand the same with an example. Select a blank model from Simulink page as shown below − It will open a blank model workspace as shown below − Click on Simulink Library browser to drag some blocks in the model workspace. Consider that in the model, we want to add two given numbers. So let us pick the Add block, the display block and the constant block. The constant block has one output connector, the Add block has two input connectors and the display block has one input connector respectively. You can drag the link from one output to another input as shown below. Here, we have two constants with values 10 and 20. They are connected to the add block with lines. The add block is connected to display with a line. When the lines are connected, the display is as follows − Now click on Run to see the result in the display block. It will add 10 + 20 to give the result as 30 in the display block. Print Page Previous Next Advertisements ”;

MATLAB Simulink – Home

MATLAB Simulink Tutorial PDF Version Quick Guide Resources Job Search Discussion MATLAB (Matrix Laboratory) is a programming language developed by a computer software company MathWorks. Simulink is a simulation and model-based design environment for dynamic and embedded systems, which are integrated with MATLAB. Simulink is also developed by MathWorks. This tutorial is designed to give students fluency in MATLAB Simulink. Problem-based examples have also been given in simple and easy way to make your learning fast and effective. Audience This tutorial has been prepared for the beginners to help them understand basic to advanced functionality of MATLAB Simulink. After completing this tutorial you will find yourself at a moderate level of expertise in using Simulink from where you can take yourself to next levels. Prerequisites We assume you have a little knowledge of any computer programming and understand concepts like variables, constants, expression, statements, etc. If you have done programming in any other high-level programming language like C, C++ or Java, then it will be very much beneficial and learning MATLAB Simulink will be like a fun for you. Print Page Previous Next Advertisements ”;

MATLAB Simulink – Blocks

MATLAB Simulink – Blocks ”; Previous Next In this chapter, we will learn about one of the basic elements in Simulink. These are termed as blocks. Blocks in Simulink helps to create models. You can make use of a Simulink library browser that has different types of blocks for creating a model. First, open a blank model. The display will be as shown below − You can save your model by clicking on the Save button. Hence, your changes will be saved successfully. Now, open the library browser to get the blocks into your model canvas. The two ways to select the blocks are as follows − Using Simulink browser library. Searching for block inside model canvas. Simulink browser library Open the Simulink library browser as shown below − If you looking for a specific block and don’t know which library, you can search for it inside the search block which is available as shown below − Here, we got all the blocks related to Sine. You can also go inside the library and pick your block. Add block, Product block etc. The display will be as shown below − To bring the block inside your model, you can select the block and drag it inside your model, as shown below − Another way is to right click the block and add to your current model. An example for the same is given below − We have not saved our model. Hence, it comes as untitled. Now, you can add to the model untitled. The block will be seen inside your mode. Searching for block inside model canvas Another way to add blocks to your model is to click inside the model and type the name of the block. It will search in the library browser and list all the model as per what you have typed. An example for the same is given below − We have typed Sine and it displays all the blocks related to sine. Print Page Previous Next Advertisements ”;

Build Model & Apply If-else Logic

Build Model & Apply If-else Logic ”; Previous Next In this chapter, we will create a model and apply if-else logic to it. Let us first collect blocks to create our model. Now, open MATLAB Simulink (blank model) and the Simulink library browser as shown below − Click on the Blank Model and open Simulink library browser as shown below − The blocks we require to build the model with if-else logic is as follows − Constant block from Commonly used blocks Switch block from Signal Routing Display block from Sinks Let us now get all the blocks together to create a model as shown below − Let us now connect the lines with each block. So you can see that the constant block has one output and the switch has three inputs and one output. We are going to connect them to the display block. After connecting the lines, the model is as shown below − Now, double click the switch block and add a threshold. The threshold value will be compared with the block in the center. Based on the constant value of the middle block, the first block value will be displayed or the last constant block value will be displayed. Let us add a threshold value to the switch as shown below − The threshold value given is 3. Click on OK to update the threshold. Now the threshold value is seen inside the switch block as shown below − The middle constant block will be compared with the switch threshold and accordingly the display will be decided. Let us now update the middle constant block with some value as shown below − The value of the constant block is 1. Let us now change the first constant block and give it a value as 0.5 as shown below − Let us now change the last constant with value as 2.5 as shown below − Hence, the first constant value is 0.5, the middle constant value is 1 and the last one is 2.5. The middle constant value 1 will be compared to switch threshold value i.e. 3 as (1 >3). It will print the value as 2.5 the last constant value. Click on the run button to get the output in the display block as shown below − Let us now change the middle constant to a higher value than the threshold of switch and see the output − The value is changed from 1 to 3.5. Click on OK and run the model to see the output in the display − Now, since the value of the middle constant is greater, the value from the first constant is printed in display. If it is less, then the value from the last constant will be printed. Print Page Previous Next Advertisements ”;

Matlab Matrix – Discussion

Discuss Matlab-Matrix ”; Previous Next MATLAB is a programming language developed by MathWorks. It started out as a matrix programming language where linear algebra programming was simple. It can be run both under interactive sessions and as a batch job. This tutorial gives you aggressively a gentle introduction of MATLAB programming language. It is designed to give students fluency in MATLAB programming language. Problem-based MATLAB examples have been given in simple and easy way to make your learning fast and effective. Print Page Previous Next Advertisements ”;

Matlab-Matrix – Multiplication

Matlab-Matrix – Multiplication ”; Previous Next Consider two matrices A and B. If A is an m x n matrix and B is an n x p matrix, they could be multiplied together to produce an m x n matrix C. Matrix multiplication is possible only if the number of columns n in A is equal to the number of rows n in B. In matrix multiplication, the elements of the rows in the first matrix are multiplied with the corresponding columns in the second matrix. Each element in the (i, j)thposition, in the resulting matrix C, is the summation of the products of elements in ith row of the first matrix with the corresponding element in the jth column of the second matrix. Matrix multiplication in MATLAB is performed by using the * operator. Example Consider following example in MATLAB a = [ 1 2 3; 2 3 4; 1 2 5]; b = [ 2 1 3 ; 5 0 -2; 2 3 -1]; prod = a * b Output The execution in MATLAB will display the following result − >> a = [ 1 2 3; 2 3 4; 1 2 5]; b = [ 2 1 3 ; 5 0 -2; 2 3 -1]; prod = a * b prod = 18 10 -4 27 14 -4 22 16 -6 >> The mtimes function You can also make use of the function mtimes to multiply two given matrices. It is a builtin function available in MATLAB. Example Consider following example − a = [ 1 2 3; 2 3 4; 1 2 5]; b = [ 2 1 3 ; 5 0 -2; 2 3 -1]; test= mtimes(a,b) Output On execution in MATLAB the output is as follows − >> a = [ 1 2 3; 2 3 4; 1 2 5]; b = [ 2 1 3 ; 5 0 -2; 2 3 -1]; test= mtimes(a,b) test = 18 10 -4 27 14 -4 22 16 -6 >> Print Page Previous Next Advertisements ”;

Matlab Matrix – Useful Resources

Matlab-Matrix – Useful Resources ”; Previous Next The following resources contain additional information on Matlab-Matrix. Please use them to get more in-depth knowledge on this. Useful Links on Matlab-Matrix Matlab-Matrix Documentation − Matlab-Matrix”s official website for its latest docs and updates. Useful Books on Matlab-Matrix To enlist your site on this page, please drop an email to [email protected] Print Page Previous Next Advertisements ”;

Matlab-Matrix – Working with Matrices

Matlab-Matrix – Working with Matrices ”; Previous Next In this chapter, I will deal with how to run the matrix inside MATLAB Environment to get the output. To define a matrix, and other matrix operations are discussed in details in the next chapters. To get the matrix output in MATLAB will make use of − Command Prompt Using m-file Using Command Prompt You can execute matrices directly inside command prompt. Here is an example wherein we have two matrices a and b. The operation a+b gives the sum of matrix a and b. The operation a-b gives the subtraction of matrix a and b. The output is command prompt is as shown below − >> a = [ 1 2 3 ; 4 5 6; 7 8 9]; >> b = [ 7 5 6 ; 2 0 8; 5 7 1]; >> c = a + b c = 8 7 9 6 5 14 12 15 10 >> d = a – b d = -6 -3 -3 2 5 -2 2 1 8 >> Using m-file You can also make use of a file to write the code and later execute it inside command prompt as shown below − Click on New script as shown below − This is open a new unsaved file as shown below − Save the file and write your code inside The file is saved as testmatrix.m. Now you can use the run button or type the name of the file inside command window. The output will be shown in the command window as shown below − >> testmatrix c = 8 7 9 6 5 14 12 15 10 d = -6 -3 -3 2 5 -2 2 1 8 >> Print Page Previous Next Advertisements ”;