Monday, 16 December 2013

How to write own function in Simulink?

Simulink is an environment for simulation and model-based design for dynamic and embedded systems. It provides an interactive graphical environment and a customizable set of block libraries that let you design, simulate, implement, and test a variety of time-varying systems, including communications, controls, signal processing, video processing, and image processing. 

Simulink offers: 
1.  A quick way of develop your model in contrast to text based-programming language such as e.g., C.  
2. Simulink has integrated solvers. In text based-programming language such as e.g., C you need to write your own solver.

Start using Simulink:

The Simulink Library Browser is the library where you find all the blocks you may use in Simulink. Simulink software includes an extensive library of functions commonly used in modeling a system. These include: 

1. Continuous and discrete dynamics blocks, such as Integration, Transfer functions, Transport Delay, etc.  
2. Math blocks, such as Sum, Product, Add, etc 
3.  Sources, such as Ramp, Random Generator, Step, etc
After typing Simulink in command window it will open following window, 

Writing own function definition using Simulink for addition, subtraction, multiplication division and average of two numbers:
1. 1st click on “user defined function” icon. Then click on “Embedded MATALB function” as shown in following figure and drag that block into new window.
2. Double click on that block. It will open one function file.  Then write program for two inputs and five outputs in that file as shown in following figure.
3. After wiring simply save that file with any name.
4. Now we require two constant inputs. Click on “Sources” and take two “Constant” blocks as shown in following figure. Connect that blocks with two inputs function block.
5. For displaying output values we require five display blocks. Just click on “sink” icon and take five display blocks as shown in following figure. Then assign two input constant values. After saving program simply run that program.  

Final Program with Function looks like following figure.

No comments:

Post a Comment