Fundamentals
Dr. U D Dwivedi
Assistant Professor (Electrical Engineering)
Room No. 202, Rajiv Gandhi Institute of Petroleum Technology,
Ratapur Chowk,
Rae Bareli -229316 INDIA
What is SIMULINK?
Contents
Basic Concepts
Starting Simulink
Simulink is started from the MATLAB
command prompt by entering the following
command: simulink
Alternatively, you can click on the "Simulink
Library Browser" button at the top of the
MATLAB command window as shown below:
10
11
Basic Elements
There are two major classes of elements in
Simulink: blocks and lines.
Blocks are used to generate, modify, combine,
output, and display signals.
Lines are used to transfer signals from one
block to another.
12
Blocks
13
Contd...
14
Lines
Lines can never inject a signal into another line; lines must be
combined through the use of a block such as a summing junction.
A signal can be either a scalar signal or a vector signal. For SingleInput, Single-Output systems, scalar signals are generally used. For
Multi-Input, Multi-Output systems, vector signals are often used,
consisting of two or more scalar signals. The lines used to transmit
scalar and vector signals are identical. The type of signal carried by
a line is determined by the blocks on either end of the line.
15
Building a System
This model will consist of three blocks: Sine Wave, Gain, and
Scope. The Sine Wave is a Source Block from which a
sinusoidal input signal originates. This signal is transferred
through a line in the direction indicated by the arrow to the Gain
Math Block. The Gain block modifies its input signal (multiplies
it by a constant value) and outputs a new signal through a line to
the Scope block. The Scope is a Sink Block used to display a
signal (much like an oscilloscope).
16
Running Simulations
17
18
19
21
22
23
In the right hand side you can see the integrator. Click on it and
drag the block inside the window just opened. Repeat this
operation as, we need two integrators. By now, your window
should look like below:
24
To model our system we need two more gain blocks and one
sumator block. We can find these two blocks in the Math section.
25
26
27
where, the first gain represents the c/m term and the second
one represents the term k/m
28
Initial Conditions
Now, we do have our model in Simulink. It is easy to imagine that the mass will not move because there
is no force acting on it. With no force motion is possible if the initial conditions are not zero. As the
equation of motion is a second order differential equation, there are two initial conditions. Right click on
the second integrator. Choose "Block Parameters".
29
30
31
32
OR
33
Run the simulation. To see the results, double click on the two
scopes. The results can be seen below It can be seen that the
initial value for position is 1 while the initial value for velocity is 0.
34
Introduction to Symbolic
Toolbox
Symbolic Objects?
36
37
Symbolic Objects
ans =1.4142
the result is
a =2^(1/2)
double(a) results in
ans = 1.4142
38
39
40
41
42
43
'1.999999999999a'*2^(-4)
44
ans =
1/10+eps/40
Fourth Option is: option 'd' that returns
the decimal expansion of t up to the number of significant
digits specified by digits:
>>sym(t,'d')
ans =
.10000000000000000555111512312578
Default value of d is 32
45
x = sym('x','real');
y = sym('y','real');
z = x + i*y
46
>>syms a b c
>>A = [a b c; b c a; c a b]
which return A =
[ a, b, c ]
[ b, c, a ]
[ c, a, b ]
Since A is circulant, the sum over each row and column is the same. To
check this for the first row and second column, enter the command
>>sum(A(1,:))
which returns ans =
a+b+c
The command sum(A(1,:)) == sum(A(:,2)) % This is a logical test.
returns ans =
1
47
Then command
>>A = subs(A,b,alpha)
return
A=
[ a, alpha, c]
[ alpha, c, beta]
[ c, a, alpha]
48
Calculus:
Solving Equations
Linear Algebra:
Variable-Precision Arithmetic:
49
Calculus
Differentiation
To illustrate how to take derivatives using the Symbolic
Math Toolbox, first create a symbolic expression:
syms x
f = sin(5*x)
50
51
Limits
52
Integration
53
Example
54
55
56
57
1
1
1.2
1.4
1.6
1.8
2
x
2.2
2.4
2.6
2.858
59
ezplot(f)
-2
-4
-6
-4
-2
0
x
60
61
ezplot(f2)
axis([-2*pi 2*pi -5 2])
title('Graph of f2')
Graph of f2
2
-1
-2
-3
-4
-5
-6
-4
-2
0
x
62
syms x
f = x^3-6*x^2+11*x-6
g = (x-1)*(x-2)*(x-3)
h = -6+(11+(-6+x)*x)*x
x3 - 6 x2 + 11 x - 6
(x - 1) (x - 2) (x - 3)
-6 + (11 + (-6 + x) x) x
63
Command: collect
64
expand
factor
If f is a polynomial with
rational coefficients, the
statement factor(f)
expresses f as a product
of polynomials of lower
degree with rational
coefficients.
65
Simplify
66
Substitutions
These commands
syms a x
s = solve(x^3+a*x+1)
67
68
Examples:
Single input: Suppose a = 980 and C1 = 3 exist in the
workspace. The statement
>> y = dsolve('Dy = -a*y')
y = exp(-a*t)*C1
produces
produces
Single Substitution:
subs(a+b,a,4)
returns
4+b.
Multiple Substitutions:
subs(cos(a)+sin(b),{a,b},{sym('alpha'),2})
cos(alpha)+sin(2)
returns
69
Integral Transforms
Fourier transform
fourier
ifourier
Inverse z-transform
iztrans
Laplace transform
laplace
z-transform
ztrans
70
Syntax
F = fourier(f)
F = fourier(f,v)
F = fourier(f,u,v)
71
72
73
Laplace transform
Syntax
laplace(F)
laplace(F,t)
laplace(F,w,z)
74
75
Some Examples ..
syms
dsolve
solve
pretty
diff
76
n = 4;
D = diff(log(A))
A = x.^((0:n)'*(0:n))
D=
A=
[
[
[
[
[
1, 1, 1, 1, 1]
1, x, x^2, x^3, x^4]
1, x^2, x^4, x^6, x^8]
1, x^3, x^6, x^9, x^12]
1, x^4, x^8, x^12, x^16]
[
[
[
[
[
0,
0,
0,
0,
0,
0,
1/x,
2/x,
3/x,
4/x,
0, 0, 0]
2/x, 3/x, 4/x]
4/x, 6/x, 8/x]
6/x, 9/x, 12/x]
8/x, 12/x, 16/x]
77
x=
1/2/a*(-b+(b^2-4*a*c)^(1/2))
1/2/a*(-b-(b^2-4*a*c)^(1/2))
78
x=
1/6/a*(36*b*c*a-108*d*a^2-8*b^3+12*3^(1/2)*(4*a*c^3-c^2*b^218*b*c*a*d+27*d^2*a^2+4*d*b^3)^(1/2)*a)^(1/3)-2/3*(3*a*c-b^2)/a/(36*b*c*a-108*d*a^28*b^3+12*3^(1/2)*(4*a*c^3-c^2*b^2-18*b*c*a*d+27*d^2*a^2+4*d*b^3)^(1/2)*a)^(1/3)1/3*b/a
-1/12/a*(36*b*c*a-108*d*a^2-8*b^3+12*3^(1/2)*(4*a*c^3-c^2*b^218*b*c*a*d+27*d^2*a^2+4*d*b^3)^(1/2)*a)^(1/3)+1/3*(3*a*c-b^2)/a/(36*b*c*a-108*d*a^28*b^3+12*3^(1/2)*(4*a*c^3-c^2*b^2-18*b*c*a*d+27*d^2*a^2+4*d*b^3)^(1/2)*a)^(1/3)1/3*b/a+1/2*i*3^(1/2)*(1/6/a*(36*b*c*a-108*d*a^2-8*b^3+12*3^(1/2)*(4*a*c^3-c^2*b^218*b*c*a*d+27*d^2*a^2+4*d*b^3)^(1/2)*a)^(1/3)+2/3*(3*a*c-b^2)/a/(36*b*c*a-108*d*a^28*b^3+12*3^(1/2)*(4*a*c^3-c^2*b^2-18*b*c*a*d+27*d^2*a^2+4*d*b^3)^(1/2)*a)^(1/3))
-1/12/a*(36*b*c*a-108*d*a^2-8*b^3+12*3^(1/2)*(4*a*c^3-c^2*b^218*b*c*a*d+27*d^2*a^2+4*d*b^3)^(1/2)*a)^(1/3)+1/3*(3*a*c-b^2)/a/(36*b*c*a-108*d*a^28*b^3+12*3^(1/2)*(4*a*c^3-c^2*b^2-18*b*c*a*d+27*d^2*a^2+4*d*b^3)^(1/2)*a)^(1/3)1/3*b/a-1/2*i*3^(1/2)*(1/6/a*(36*b*c*a-108*d*a^2-8*b^3+12*3^(1/2)*(4*a*c^3-c^2*b^218*b*c*a*d+27*d^2*a^2+4*d*b^3)^(1/2)*a)^(1/3)+2/3*(3*a*c-b^2)/a/(36*b*c*a-108*d*a^28*b^3+12*3^(1/2)*(4*a*c^3-c^2*b^2-18*b*c*a*d+27*d^2*a^2+4*d*b^3)^(1/2)*a)^(1/3))
79
pretty(x)
[
1/3
2
]
[ %1
3ac-b
]
[1/6 ----- - 2/3 ---------- - 1/3 b/a]
[
a
1/3
]
[
a %1
]
[
1/3
2
[
%1
3ac-b
[- 1/12 ----- + 1/3 ---------- - 1/3 b/a
[
a
1/3
[
a %1
/
1/3
2\]
1/2 | %1
3 a c - b |]
+ 1/2 I 3 |1/6 ----- + 2/3 ----------|]
|
a
1/3 |]
\
a %1 /]
[
1/3
2
[
%1
3ac-b
[- 1/12 ----- + 1/3 ---------- - 1/3 b/a
[
a
1/3
[
a %1
/
1/3
2\]
1/2 | %1
3 a c - b |]
- 1/2 I 3 |1/6 ----- + 2/3 ----------|]
|
a
1/3 |]
\
a %1 /]
2
3
%1 := 36 b c a - 108 d a - 8 b
1/2
3 2 2
2 2
3 1/2
+ 12 3 (4 a c - c b - 18 b c a d + 27 d a + 4 d b )
80
% The statment
x = solve('p*sin(x) = r');
% chooses 'x' as the unknown and returns
x
x=
asin(r/p)
81
x=
1
3
y=
1
-3/2
82
S.y
ans =
1
-3/2
83
u=
1/2/(a+1)*(-2*a+2*(-a)^(1/2))+1
1/2/(a+1)*(-2*a-2*(-a)^(1/2))+1
v=
1/2/(a+1)*(-2*a+2*(-a)^(1/2))
1/2/(a+1)*(-2*a-2*(-a)^(1/2))
84
a=
2
2
3
3
u=
1/3+1/3*i*2^(1/2)
1/3-1/3*i*2^(1/2)
1/4+1/4*i*3^(1/2)
1/4-1/4*i*3^(1/2)
v=
-2/3+1/3*i*2^(1/2)
-2/3-1/3*i*2^(1/2)
-3/4+1/4*i*3^(1/2)
-3/4-1/4*i*3^(1/2)
85
x=
-.66870120500236202933135901833637
-.33129879499763797066864098166363
y=
-1.5528386984283889912797441811191
-1.8902411084331130499424622177919
86
y=
C1*exp(-a*t)
87
y=
exp(-a*t)
88
y=
cos(a*t)
89
y=
-sin(t)
sin(t)
90
Thank you.......