Friday, 13 January 2012

MATLAB SIMULINK EXAMPLES

Example 1. Simulation of an Equation.
In this example we will use Simulink to model an equation. Let's consider
ha
(1)
where the displacement x is a function of time t, frequency w, phase angle phi, and amplitude A. In this example the values for these parameters are set as follows: frequency=5 rad/sec;phase=pi/2;A=2.

1. From Simulink's library drag the following blocks to the Model Window

Blocks to be dragged to the model window Where located in Simulink library browser
Ramp Sources
Constant Sources
Gain Math Operation
Sum Math Operation
Product Math Operation
Trigonometry Function Math Operation
Scope Sinks
Mux Signal Routing
2. The next step is to connect these blocks as shown in Figure E1-1.


Figure E1-1

Double click on the blocks and enter the appropriate values as prompted by the pop-up dialog windows. Note that the cosine function can be selected from the pull-down menu in the pop-up window. In the arrangement shown above, the input signal (a ramp function) is to be displayed along with the output (displacement) via the use of the mux tool as demonstrated earlier in this tutorial. To view the plots, double click on the scope.


3. Make sure all blocks are connected correctly then run the simulation (CTRL+T). You may need to select the Auto scale button on the scope display window to obtain a better display of the plots.
You may find the sinusoidal plots to be a bit "jaggy". You may want to improve the resolution of the displayed plot by redefining the Max Step Side value ("auto" is set a default value) in Simulation Parameters window (with keystrokes CTRL+E in the model window). Just for fun, you may want to experiment with different choice of solver. ODE45 is a default choice. You are encouraged to learn more about the solver methods by checking out the help files in Matlab command window.

This example has demonstrated the use Simulink with built-in mathematical functions and other supporting toolboxes to simulate an equation. The same output/result can also be obtained with the following set of instructions entered in Matlab command window:

>> t=(0:.01:10);A=2;phi=pi/2;omega=5;
>> xt=A*cos(omega*t+phi);
>> plot(t,xt);grid

REFERENCE:http://edu.levitas.net/Tutorials/Matlab/Simulink/examples.html

No comments:

Post a Comment