Sie sind auf Seite 1von 12

Instruction Manual for MATLAB

Command Window:
The Command window is the main window. Use the Command Window
to enter variables and to run functions and M-files scripts (more about m-
files later).

You type all your commands after the command Prompt “>>”, e.g., defining the
following matrix.

Write the following snippet on the command window , make sure to press enter
after each line of code and don’t miss the semi-colons.
By implementing the above snippet, we have just defined a transfer function:
G = 1/(s^2 +6s +25). There is also another way of defining a transfer function and
it is given below:

Notice the ‘clc’ at the end. It is used to clear the contents of the command
window.(Executing clc only clears command window, values stored in variables
are still intact).
After defining our transfer function we must see the Pole-zero plot of the system
‘G(s)’.
It can be implemented as:

A Pole-Zero map pops up. You can see two ‘x’ signs here at -3±4j .These ‘x’ sign
represents the poles of the systems. So the two poles of the system are at -3±4j.
You can type – ‘grid on’ on the command window and press enter.
Turning on the grid displays lines of constant damping ratio (zeta) and lines of
constant natural frequency (wn).

Right click on the plot and go to Properties.

In properties dialog box go to ‘Limits’ tab and change the limits accordingly.
After setting the limits, click on the two ‘x’s(poles), and you can get information
about pole location, damping, % overshoot and natural frequency.
Now, for obtaining the step response of the system write “step(G);” command and
the step response window will appear.
Syntax for step response – step(G,Tfinal); (here Tfinal defines the limit of time
axis )
now run and see step response of the system up to 5 secs by implementing -
step(G,5); it is left as student’s exercise.

Right click on the plot, go to characteristics and select peak response, settling
time, etc
The figure above shows the peak response of the system. Student should
similarly find our setting time, rise time,etc. (verify that settling time = 1.195s, rise
time = 0.371s)

Impulse response
To find out the impulse response of the system use the command – impulse(G);
Find out the peak response and the settling time for this impulse response in a
similar way as you found those in step response.

You can also view the step and impulse responses for multiple systems
simulataneously . You can use the syntax – step(G1,G2,…Gn); and
impulse(G1,G2,….Gn); where G1,G2…Gn are differnt systems.

Now we will illustrate the Bode Plot of this system.

Bode Plot: type - bode(G); and bode plot will appear.


Click on the plot and a black dot will appear, you can drag this marker and see
magnitude and phase at different points.

Now we will see how to optimize this process and create and simulate any
second order system with desired ‘zeta’ and natural frequency.

Click on ‘New script’ button. on the top left side of the window

write the following code. Save this ‘.m’ file on the MATLAB folder and click on

Run.

In the command window below enter the value of zeta and then enter the value of
natural frequency. Your desired second order function will appear in the
command window and pzplot and step response will also appear on separate
windows.

Matlab code for the above illustration:


%transfar function & response of a 2nd order system
% zeta is tha damping factor
%wn is natural frequency
zeta=input('enter zeta ');
wn=input('enter wn in rad/sec ');
num=[wn^2];
den=[1 2*zeta*wn wn^2];
G=tf(num,den) %% get transfar function
ltiview(G)%% various plots to show response
impulse(G);
pzplot(G);
The desired plots for a second order system with zeta = 0.5 and wn = 2.

Das könnte Ihnen auch gefallen