Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Matlab Simulation Examples

3/2/01

Step Response Step Response


Mass-Damper system, Technique 1 Mass-Damper system, Technique 2
1 1

0.8 0.8
Amplitude

Amplitude
0.6 0.6

0.4 0.4

0.2 0.2

0 0
0 1 2 3 4 5 6 0 1 2 3 4 5 6
Time (sec.) Time (sec.)

Step Response Step Response


MSD System, Technique 1 MSD System, Technique 2

0.2 0.2
Amplitude

Amplitude

0.1 0.1

0 0

-0.1 -0.1

0 2 4 6 8 10 12 0 2 4 6 8 10 12
Time (sec.) Time (sec.)
% Examples of simulations using Matlab
% Two methods of simulting dynamic systems are demonstrated:
% 1. Technique 1 uses state equations
% 2. Technique 2 uses transfer functions
% Two systems are considered: a mass-damper and mass-spring-damper system.
% M.A. Minor - 3/02/01 - ME3210

clear all

% MASS-DAMPER VELOCITY SIMULATIONS (First order system)

% Technique #1 - Using state space matrices: xdot=Ax+Bu, y=Cx+Du


% Defining system variables
m=1;
b=1;

% Defining the A,B,C,D matrices


A=-b/m;
B=1/m;
C=1;
D=0;

sys=ss(A,B,C,D)
subplot(2,2,1) %figure(1)
% The step command simulates the response of the system to a step input and plots the
result.
step(sys);
title('Mass-Damper system, Technique 1')

% Technique #2 - Using the coefficients of the transfer function, V(s)/F(s)=(1/(ms+b))


num=1;
den=[m b]
sys=tf(num,den)
subplot(2,2,2) %figure(2)
step(sys);
title('Mass-Damper system, Technique 2')

% MASS-SPRING-DAMPER VELOCITY SIMULATIONS (Second order system)


% Simulating a second order system is very similar. Consider a MSD system:
k=10;

% First by technique 1:
subplot(2,2,3) %figure(3)
A=[-b/m -1/m
k 0]
B=[1/m 0]'
C=[1 0]
D=[0]
sys=ss(A,B,C,D);
step(sys);
title('MSD System, Technique 1')

% Technique 2: transfer function,


subplot(2,2,4) %figure(4)
num=[1 0];
den=[m b k];
sys=tf(num,den);
step(sys)
title('MSD System, Technique 2')

You might also like