Professional Documents
Culture Documents
Presented by
M.Venkateshkumar, M.E.,(Ph.D)
Asst Prof (GI)
Dept of EEE
AVIT
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
Contents
Introduction to Matlab
M-file
Simulink
Simpower System toolbox
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
Introduction to Matlab
What is Matlab?
MATrix LABoratory
Powerful, extensible, highly integrated
computation, programming, visualization, and
simulation package
Widely used in engineering, mathematics, and
science
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
MATLAB system
Language: arrays and matrices, control flow, I/O,
data structures, user-defined functions and scripts
Working
Environment:
editing,
variable
management, importing and exporting data,
debugging, profiling
Graphics system: 2D and 3D data visualization,
animation and custom GUI development
Mathematical Functions: basic (sum, sin,) to
advanced (fft, inv, Bessel functions, )
API: can use MATLAB with C, Fortran, and Java, in
either direction
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
Matlab screen
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
Editor window
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
Command Window
Type commands
Current Directory
View folders and m-files
Workspace
View program variables
Double click on a variable to see it in the
Array Editor
Command History
View past commands
Save a whole session using diary
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
M-File
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
10
Operators (arithmetic)
+ ----> addition
- ----> subtraction
* ---> multiplication
/ ---> division
^ ---> power
---> complex conjugate transpose
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
11
M-files
Addition
>> a =10;
>> b =20;
>> c = a+b (press enter)
Ans 30.
Subtraction
>>D= a-b;
Ans -10.
6/9/2011
Multiplication
>> a =10;
>> b =20;
>> E= a*b
Ans 200.
Divided
>>F= a/b;
Ans 0.5.
Multi operation
>> g= (a+b)/(a*b)
g=
M.Venkateshkumar,M.E.,(Ph.D)
0.1500
12
Complex Number
a+ib
>> 5+10i
ans =
5.0000 +10.0000i
Multiplication
>> d = a*b
d=
-40.0000 +45.0000i
Addition
>> a =5+10i;
>> b =2+5i;
>> c = a+b
c=
7.0000 +15.0000i
Division
>> e = a/b
e=
2.0690 - 0.1724i
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
13
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
14
Square root
command----->sqrt(x)
6/9/2011
>> sqrt(4)
ans =
2
>> sqrt(16)
ans =
4
>> sqrt(625)
ans =
25
>> sqrt(12345)
ans =
111.1081 M.Venkateshkumar,M.E.,(Ph.D)
15
Matrix operation
>> a = [1 2; 3 4]
a=
1
3
Addittion
>> c = a+b
c=
2
4
6 8
10 12
>> b = [5 6;7 8]
Subtraction
>>d = a-b
b=
d=
5
7
6/9/2011
6
8
-4 -4
-4 -4
M.Venkateshkumar,M.E.,(Ph.D)
16
Matrix Multiplication
>> f = a*b
f=
19 22
43 50
Matrix Division
>> e = a/b
e=
3.0000 -2.0000
2.0000 -1.0000
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
17
Matrix Transpose ()
3x3 matrix
>> a = [1 2 3; 4 5 6; 7 8 9]
a=
1
4
7
2
5
8
3
6
9
a transpose
>> b = a'
b=
1
2
3
4
5
6
6/9/2011
7
8
9
M.Venkateshkumar,M.E.,(Ph.D)
18
Determinants
Command = det(a)
>> a = [1 2; 3 4]
a=
1
2
3
4
>> b= det(a)
b=
-2
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
19
Inverse Matrix
Syntax inv(a)
>> a = [ 1 2 ; 3 4]
a=
1 2
3 4
>> inv(a)
ans =
-2.0000 1.0000
1.5000 -0.5000
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
20
Array
Vector a:
>> a = [1 2 3 4]
a=
Vector b:
>> b = [ 5 7 8 9]
Find length
>> a = [ 1 2 3 4]
a=
1
2
3 4
>> length(a)
ans =
4
b=
5
6/9/2011
9
M.Venkateshkumar,M.E.,(Ph.D)
21
Graph
Syntax
Syntax ------> plot(x,y)
Syntax ------> plot(x,y), xlabel(a),ylabel(b)
Syntax ------> plot(x,y), xlabel(a),ylabel(b),title(c)
Syntax ------> plot(x,y) , grid on
Syntax------> plot(x,y), legend( a , b )
Syntax------> bar(x,y)
Syntax -----> polar(x,y)
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
22
Graph
1
Command--->plot(x)
Sin wave
[start:interval:end]
>> a = [1:1:100];
>> b = sin(a);
>> plot(b)
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
6/9/2011
10
M.Venkateshkumar,M.E.,(Ph.D)
20
30
40
50
60
70
80
90
100
23
Graph
>> x = [ 0:0.1:10];
>> y = cos(x);
>> plot(x,y)
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
24
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
25
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
26
Grid on
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
27
Bar Graph
command ----->bar(a,b)
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
28
Polar Graph
command---->polar( a ,b )
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
29
6/9/2011
Color
Specifier
White
Black
Blue
Red
Cyan
Green
Magenta
Yellow
y
M.Venkateshkumar,M.E.,(Ph.D)
30
Examples
>> x = [-5:0.01:5];
>> y = sin(x);
>> z = cos(x);
>> plot(x,y,'b',x,z,'r')
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
31
Log sheet
command-----> loglog(x)
>> a = [1:1:10];
>> b = [1:2;20];
>> b = [1:2:20];
>> loglog ( a,b), grid on
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
32
Mesh grid
command ----> mesh(x,y,z)
>> a = [1 2 3; 3 2 4; 5 6 7];
>> b = [ 2 4 5; 6 4 5; 7 8 8];
>> c = [ 1 4 6; 2 4 6; 0 9 7];
>> mesh(a,b,c)
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
33
Algebraic Equation
Command ----> solve(x)
Problem : 1
solve ( eq 1 , eq 2)
>> a = solve('5*x+4*y=3','x-6*y');
>> x = a.x
x=
9/17
>> y = a.y
y=
3/34
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
34
Problem 2
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
35
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
36
Collecting
Collect command -----> collect(x)
>> syms x
>> collect (x*(x^2-2))
ans =
x^3 - 2*x
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
37
Differential Equations
Command -----------> diff(x)
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
38
Problem
>> syms x
>> a = 3*x^3+4*x^2+7*x+5;
>> diff(a)
ans =
9*x^2 + 8*x + 7
----------------------------------------------------------------------------------->> % Show that f(x) = x^2 satisfies -(df/dx)+2*x=0
>> syms x
>> f = x^2;
>> g = 2*x;
>> h = diff(f);
>> -h+g
ans =
0
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
39
Integration
Command -----------> int(f)
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
40
Problem
compute int(x^5cos(9x)dx
>> syms x
>> f = x^5*cos(9*x);
>> F= int(f)
F=
(40*cos(9*x))/177147 + (40*x*sin(9*x))/19683 - (20*x^2*cos(9*x))/2187 +
(5*x^4*cos(9*x))/81 - (20*x^3*sin(9*x))/729 + (x^5*sin(9*x))/9
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
41
Problem 2
>> %find int(xdx) limit [2,3]
>> syms x
>> int('x',2,3)
ans =
5/2
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
42
Problem 3
what is the area under the curve f(x) = x^2cosx for -6<=x<=6?
>> syms x
>> f = x^2*cos(x)
>> a = int(f, -6,6)
a = 24*cos(6) + 68*sin(6)
>> double (a)
ans = 4.0438
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
43
Problem 4
%calculate int(e^-x^2 sinx dx for -inf<=x<=0
>> syms x
>> f = int(exp(-x^2) * sin(x), 0, inf)
f=
-(pi^(1/2)*erf(i/2)*i)/(2*exp(1/4))
>> double(f)
ans =
0.4244
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
44
Transforms
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
45
Laplace
command -----> laplace (x)
>> syms a t
>> laplace (a)
ans =
1/s^2
-------------------->> laplace(t^2)
ans =
2/s^3
6/9/2011
>> laplace(t^7)
ans =
5040/s^8
------------------>> laplace(t^5)
ans =
120/s^6
M.Venkateshkumar,M.E.,(Ph.D)
46
>> syms b t w
>> laplace(exp(-b*t))
ans =
1/(b + s)
----------------------------->> laplace(cos(w*t))
ans =
s/(s^2 + w^2)
-------------------------------
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
47
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
48
Fourier Transforms
command--------> fourier(x)
>> syms x
>> fourier (sin(x))
ans =
-pi*(dirac(w - 1) - dirac(w + 1))*I
------------------------------------------------------------------------------------------------->> f = exp(-2*x^2);
>> fourier(f)
ans =
(2^(1/2)*pi^(1/2))/(2*exp(w^2/8))
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
49
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
50
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
51
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
52
Waveform
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
53
Simulink
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
54
Introduction to Simulink
Simulink is a platform for multi-domain simulation and
Model- Based design of dynamic systems and embedded
systems
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
55
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
56
Starting Simulink
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
57
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
58
Press
6/9/2011
Launching simulink
M.Venkateshkumar,M.E.,(Ph.D)
59
Simulink Tool
Blocks
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
60
Constant Value
In1
Constant
1
Out1
Addition Block
Add
t
Display the value
sinwave
Sine Wave
Function
Display
subtract Block
Subtract
Multiplication
Product
division Block
6/9/2011
Divide
M.Venkateshkumar,M.E.,(Ph.D)
61
Random
Number
ground
dumux
Ground
sum of all element
mux
Sum of
Elements
clock
create matrix
Clock
1
2
gain
Matrix
Concatenate
Gain
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
62
f(u)
1
s
Fcn
integrator
Integrator
code generation
fcn
two diemensional
MATLAB Function
XY Graph
pulse generation
Re
Im
Pulse
Generator
complex number
Complex to
Real-Imag
power graphical user interface
Continuous
powergui
In1
Out1
Subsystem
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
63
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
64
Double click
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
Double click
65
Running simulation
Double click to
view the Result
waveform
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
66
Result
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
67
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
68
Complex Number
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
69
Track the
system
block and
create
the subsystem
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
70
Create Subsystem
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
71
Matrix
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
72
Matrix Addition
Matrix subtraction
Matrix Multiplication
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
73
Matrix Addition
Matrix subtraction
Matrix Multiplication
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
74
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
75
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
76
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
77
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
78
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
79
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
80
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
81
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
82
Example
Continuous
powergui
Scope
Scope1
b
c
b2
c2
Bb
Cc
a2
Aa
Three-Phase
Three-Phase
Three-Phase
Three-Phase
Parallel RLC
Load1
Parallel RLC Load6 Parallel RLC Load7 Parallel RLC Load8
M.Venkateshkumar,M.E.,(Ph.D)
c2
IM
b2
Bb
Cc
B2
A
a2
Aa
Three-Phase Transformer
Inductance Matrix Type
(Two Windings)1
IM
Three-Phase
Three-Phase
Three-Phase
Parallel RLC Load2 Parallel RLC Load3 Parallel RLC Load4
6/9/2011
Three-Phase
V-I Measurement1
Three-Phase Transformer
Inductance Matrix Type
(Two Windings)
B1
Three-Phase Source1
Iabc
Three-Phase
V-I Measurement
Three-Phase Source
Vabc
Iabc
Vabc
Three-Phase
Parallel RLC Load5
83
Result
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
84
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
85
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
86
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
87
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
88
6/9/2011
M.Venkateshkumar,M.E.,(Ph.D)
89