Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
9 views

MATLAB Programming Lecture 1

Uploaded by

Ahmed Lasheen
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

MATLAB Programming Lecture 1

Uploaded by

Ahmed Lasheen
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 48

for internal use only Automation

Dr./ Essam and


Nabil
Drives

Lecture No.“1”
SIMATIC HMI
MATLAB
The Human
Programming
Machine Interface
Introduction

MATLAB
MATLAB Basics

Vectors & Arrays

Math. Functions

Polynomials

MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis
The Language of
Curve fitting Technical Computing
Symbolic math.

Signal processing
Prepared by:
Function m-file
Dr./ Essam Nabil
MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

What is MATLAB ?
SIMATIC HMI
MATLAB
The Human
Programming MATLAB :stands for MATrix LABoratory
Machine Interface
Introduction MATLAB® is a high-performance language for
MATLAB Basics
technical computing integrates computation,
Vectors & Arrays

Math. Functions
visualization, and programming in an easy-
Polynomials
to-use environment.
MATLAB plotting
MATLAB® typical uses include:
2-D & 3-D Graphics
Math and computation
Algorithm development
Flow Control
Data acquisition
System analysis
Modeling, simulation, and prototyping
Curve fitting Data analysis, exploration, and visualization
Symbolic math. Scientific and engineering graphics
Signal processing Application development, including graphical user
Function m-file interface building
MATLAB Simulink MATLAB® features a family of add-on
Final Test
application-specific solutions
Faculty of Electronic Engineering
called
Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

What is MATLAB ?
SIMATIC HMI
MATLAB
The Human
Toolboxes: are comprehensive collections
Programming
Machine Interface
of MATLAB functions (M-files) that extend the
Introduction
MATLAB Basics
MATLAB environment to solve particular
Vectors & Arrays classes of problems e.g. Control systems,
Math. Functions Communication, Image processing, Signal
Polynomials processing, Neural networks, Fuzzy logic,
MATLAB plotting Wavelets, Simulation, and many other areas.
2-D & 3-D Graphics In industry, MATLAB is the tool of choice for
Flow Control high-productivity research, development, and
System analysis analysis.
Curve fitting For any information on MATLAB®, contact
Symbolic math.
Mathworks
MATLAB makes coding
Signal processing

Function m-file
www.mathworks.com
fun!
MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Overview of the MATLAB Environment


SIMATIC HMI
MATLAB MATLAB Desktop
The Human
Programming
Machine Interface layout:
Introduction
MATLAB Basics

Vectors & Arrays

Math. Functions

Polynomials

MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Overview of the MATLAB Environment


SIMATIC HMI
MATLAB MATLAB Start Button: provides easy
The Human
Programming
Machine Interface access to tools, demos, shortcuts, and
Introduction
documentation.
MATLAB Basics

Vectors & Arrays

Math. Functions

Polynomials

MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Overview of the MATLAB Environment


SIMATIC HMI
MATLAB Overview of the Command Window: is
The Human
Programming
Machine Interface one of the main tools you use to enter data,
Introduction
run MATLAB functions and other M-files, and
MATLAB Basics

Vectors & Arrays


display results.
Math. Functions

Polynomials

MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Overview of the MATLAB Environment


SIMATIC HMI
MATLAB Overview of the Workspace Browser:
The Human
Programming
Machine Interface consists of the set of variables built up
Introduction
during a session of using the MATLAB
MATLAB Basics

Vectors & Arrays


software and stored in memory.
Math. Functions

Polynomials

MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Overview of the MATLAB Environment


SIMATIC HMI
MATLAB Overview of the Variable Array Editor:
The Human
Programming
Machine Interface double-click a variable in the Workspace
Introduction
browser to see it in the Variable Editor. Use
MATLAB Basics

Vectors & Arrays


the Variable Editor to view and edit a visual
Math. Functions
representation of variables in the
Polynomials workspace.
MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Overview of the MATLAB Environment


SIMATIC HMI
MATLAB
The Human
Programming Overview of the Command History
Machine Interface
Introduction Window: displays a log of the statements
MATLAB Basics most recently run in the Command Window,
Vectors & Arrays
copy them, execute them, and more.
Math. Functions

Polynomials

MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Overview of the MATLAB Environment


SIMATIC HMI
MATLAB Overview of the Current Directory
The Human
Programming
Machine Interface Browser: used to View files, perform file
Introduction
operations such as open, find files and file
MATLAB Basics

Vectors & Arrays


content, and manage and tune your files.
Math. Functions

Polynomials

MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Overview of the MATLAB Environment


SIMATIC HMI
MATLAB M-Files Editor and Debugger:
The Human
Programming
Machine Interface used to Create, edit, debug, and analyze M-
Introduction
files (files containing MATLAB language
MATLAB Basics

Vectors & Arrays


statements).
The Editor provides a graphical user
Math. Functions

Polynomials interface for text editing, as well as for M-file


MATLAB plotting debugging. To create or edit an M-file use File
2-D & 3-D Graphics > New or File > Open, or use the edit
Flow Control function.
System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Overview of the MATLAB Environment


SIMATIC HMI
MATLAB
The Human
Programming
Machine Interface
Introduction
MATLAB Basics

Vectors & Arrays

Math. Functions

Polynomials

MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Overview of the MATLAB Environment


SIMATIC HMI
MATLAB Overview of the Figure Window: is a
The Human
Programming
Machine Interface MATLAB window that contains graphic
Introduction
displays (usually data plots) and UI
MATLAB Basics

Vectors & Arrays


components. You create figures explicitly
Math. Functions
with the figure function, and implicitly
Polynomials whenever you plot graphics and no figure is
MATLAB plotting active.
2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Overview of the MATLAB Environment


SIMATIC HMI
MATLAB Overview of the Help Browser: is an
The Human
Programming
Machine Interface HTML browser integrated with the MATLAB
Introduction
desktop used to search and view
MATLAB Basics

Vectors & Arrays


documentation and demonstrations for
Math. Functions
MATLAB and all other installed MathWorks
Polynomials products.
MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Basic MATLAB Notations


SIMATIC HMI
MATLAB
The Human
Programming
1. MATLAB is case sensitive that the
Machine Interface
Capital letters are different from small
Introduction

MATLAB Basics
ones i.e. A ≠ a
2. Comments can de added to describe
Vectors & Arrays

Math. Functions
specific part or function by using ‘%’
Polynomials
i.e. pause %to stop execution
3. Don’t start variable or file name with
MATLAB plotting
a number.
4. Don’t use MATLAB keywords or
2-D & 3-D Graphics

Flow Control
functions-as variable or file name i.e.
System analysis
if , for, while, case, end, . . . etc
Curve fitting 5. Don’t leave space within the variable
Symbolic math. name and replace it with underscore
Signal processing
‘_’ i.e. user_name = ‘Essam’
Function m-file 6. When saving MATLAB files don’t leave
MATLAB Simulink space within the file name and replace
Final Test itof Electronic
Faculty with underscoreIndustrial
Engineering (_).Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Basic MATLAB Notations


SIMATIC HMI
MATLAB
The Human
Programming
7. The syntax of MATLAB functions must
Machine Interface
be written completely in the write
Introduction
form to avoid syntax errors.
MATLAB Basics
8. To stop program execution when
Vectors & Arrays
MATLAB is Busy press CTRL+C
Math. Functions
buttons of keyboard.
Polynomials 9. When using Command window you can
MATLAB plotting use UP ’↑’ and DOWN ‘↓’ directions to
2-D & 3-D Graphics
recall previous executed commands.
Flow Control

System analysis 10. When using Command window you can


Curve fitting use ESC button to cancel a line or
Symbolic math. function before execution.
Signal processing
11. MATLAB suppresses output -don’t
Function m-file display it on the command window- for
MATLAB Simulink those commands that terminated with
Final Test aof Electronic
Faculty semicolon Engineering ‘;’ Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Basic MATLAB Notations


SIMATIC HMI
12. To write more than one command or
MATLAB
The Human
Programming
Machine Interface
Introduction
function in the same line use comma
MATLAB Basics ‘,’ to separate them i.e.
Vectors & Arrays x=3 , y=5 , z=x+y
Math. Functions also you can use semicolon ‘;’ to
Polynomials separate commands
13. To complete writing an expression in
MATLAB plotting entered on the same line.
2-D & 3-D Graphics
new line of the program you must
Flow Control
terminate first line with ‘ . . . ‘
System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Basic Functions and Values


SIMATIC HMI
MATLAB
The Human
Programming exit :Terminate MATLAB program
Machine Interface
Introduction
(same as quit)
MATLAB Basics clc :Clear Command Window
Vectors & Arrays
clear :Remove items from workspace,
Math. Functions
freeing up
Polynomials

MATLAB plotting
system memory.
2-D & 3-D Graphics pause :Halt execution temporarily i.e.
Flow Control causes the
System analysis
currently executing M-file to
Curve fitting
stop and wait for
Symbolic math.

Signal processing
you to press any key before
Function m-file
continuing.
MATLAB Simulink keyboard :terminate the control to Input
Final Test from
Faculty keyboard
of Electronic Engineering to Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Basic Functions and Values


SIMATIC HMI
MATLAB
The Human
Programming ans :Default result name for any
Machine Interface
Introduction
expression with no
MATLAB Basics defined variable name.
Vectors & Arrays

Math. Functions
>>x=5;
Polynomials >>y=10;
MATLAB plotting
>>x+y
2-D & 3-D Graphics
>>
Flow Control

System analysis ans=


Curve fitting 15
Symbolic math.

Signal processing
NaN :The result is not a number.
Function m-file input :To request user input as:
MATLAB Simulink
user_name = input(' Enter
Final Test
your name: ')
Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Basic Functions and Values


SIMATIC HMI
MATLAB
The Human
Programming
Machine Interface
>>fprintf( format, data ) function
Introduction %d integer
MATLAB Basics
%f floating point format
Vectors & Arrays

Math. Functions
%e exponential format
Polynomials \n new line character
MATLAB plotting \t tab character
2-D & 3-D Graphics
Example;
Flow Control
>> fprintf( 'Result is %d' , 3 )
System analysis
Result is 3
Curve fitting

Symbolic math. >> fprintf( 'Area of a circle with


Signal processing radius %d is %f', 3, pi*3^2 )
Function m-file Area of a circle with radius 3 is
MATLAB Simulink 28.274334
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Handling Vectors
SIMATIC HMI
MATLAB
The Human
To enter a row vector:
Programming
Machine Interface
Introduction
>> a = [1 2 3 4]; OR >>
MATLAB Basics a = [1,2,3,4];
Vectors & Arrays To enter a column vector:
Math. Functions
>> a = [1;2;3;4];
Polynomials
To enter a regular vector with defined
MATLAB plotting
step size:
2-D & 3-D Graphics

Flow Control
>> vector_name = initial_value: step_size :
System analysis
final_value
Curve fitting
EX.: >>x=0:0.1:1
Symbolic math. x=
Signal processing 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8
Function m-file 0.9 1
MATLAB Simulink To enter a regular vector with defined
Final Test No.of Electronic
Faculty of elements:
Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Handling Vectors
SIMATIC HMI
MATLAB To enter a regular logarthimic vector
The Human
Programming
Machine Interface with defined No. of elements:
Introduction
>> vector_name =logspace( initial,final, No.of
MATLAB Basics

Vectors & Arrays


points)
Math. Functions
EX.: >>x=logspace(0,3,10)
Operation on vectors:
Polynomials >> a = [1 2 3 4];
MATLAB plotting >> b = a + 2
2-D & 3-D Graphics b=
Flow Control 3 4 5 6
System analysis >> c = a + b
Curve fitting c=
Symbolic math.
4 6 8 10
Signal processing
>> d = c * 2
Function m-file
d=
MATLAB Simulink
8 12 16 20
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Handling Vectors
SIMATIC HMI
MATLAB element-wise operations:
The Human
Programming
Machine Interface >> r1 = [2 5 7 9];
Introduction
>> r2 = [1 3 8 5];
MATLAB Basics

Vectors & Arrays


>>T1 = r1 .* r2
Math. Functions
T1=
Polynomials 2 15 54 45
MATLAB plotting Similarly: >>T2 = r1 ./ r2
2-D & 3-D Graphics >>T2 = r1 .^ r2
Flow Control

System analysis >> n = length(r2) %to evaluate length


Curve fitting
of vector r2
Symbolic math. n=
Signal processing 4
Function m-file >> a = max(r2) %to find maximum
MATLAB Simulink value of vector r2
Final Test a=
Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Handling Vectors
SIMATIC HMI
MATLAB
The Human
>> b = min(r2) %to find minimum
Programming
Machine Interface value of vector r2
Introduction b=
MATLAB Basics
1
Vectors & Arrays

Math. Functions
>> b = mean(r2) %to find average
value of vector r2
Polynomials
b=
MATLAB plotting
4.25
2-D & 3-D Graphics
>>z=r2(4)
Flow Control
z=
System analysis
5
Curve fitting

Symbolic math.
>>r2(2)=0 %replace 2nd
element value with 0
Signal processing

Function m-file
r2=
MATLAB Simulink
1 0 8 5
Final Test
>> r2(2)=[ ]
Faculty of Electronic Engineering
%remove 2nd element
Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Handling Vectors
SIMATIC HMI
MATLAB
The Human
Programming
>> x = [1 2 3 4];
Machine Interface
>> plot(x) % Linear 2-D plot of
Introduction
MATLAB Basics
vector x
Vectors & Arrays

Math. Functions

Polynomials

MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Handling Arrays ‘Matrices’


SIMATIC HMI
MATLAB
The Human
Array: is a collection of data values
Programming
Machine Interface
organized into rows and columns, and known
Introduction
by a single name.
MATLAB Basics

Vectors & Arrays Array is the fundamental unit of data in


Math. Functions MATLAB
Polynomials Scalars are also treated as arrays by MATLAB
MATLAB plotting (1 row and 1 column).
Row 1
2-D & 3-D Graphics
Row 2
Flow Control

System analysis
Row 3
Curve fitting
arr(3,2)
Symbolic math.
Row 4
Signal processing

Function m-file
Col 1 Col 2 Col 3 Col 4 Col 5
MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Handling Arrays ‘Matrices’


SIMATIC HMI
MATLAB
 Enteringmatrices into MATLAB is the same as
The Human
Programming
Machine Interface entering a vector, except each row of elements
Introduction is separated by a semicolon (;) as:
MATLAB Basics >> B = [1 2 3 4;5 6 7 8;9 10 11 12]
Vectors & Arrays B=
Math. Functions
1 2 3 4
Polynomials
5 6 7 8
MATLAB plotting
9 10 11 12
2-D & 3-D Graphics

Flow Control  Or a return as shown:


System analysis
>> B = [ 1 2 3 4
Curve fitting
5 6 7 8
Symbolic math.
9 10 11 12]
Signal processing
B=
Function m-file
1 2 3 4
MATLAB Simulink

Final Test
5 6 7 8
Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Handling Arrays ‘Matrices’


SIMATIC HMI
MATLAB
The Human
Operation on matrices:
Programming
Machine Interface
>> A = [1 2;3 4];
Introduction
MATLAB Basics
>> n = size(A) %to evaluate dimension of
Vectors & Arrays
matrix A
Math. Functions
n=
Polynomials 2 2
MATLAB plotting >> diag(A) %returns the main diagonal of
2-D & 3-D Graphics
matrix A
Flow Control
ans= 1
System analysis
4
Curve fitting
Note: If A is a vector then diag function puts it as
Symbolic math.
the main diagonal
of a diagonal matrix.
Signal processing

Function m-file
>> v=[1 2 3];
MATLAB Simulink
>>diag(v)
Final Test
ans= 1 0 0
Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Handling Arrays ‘Matrices’


SIMATIC HMI
MATLAB
The Human
>> trace(A) %to find Sum of diagonal
Programming
Machine Interface elements of matrix A
Introduction ans=
MATLAB Basics
5
Vectors & Arrays

Math. Functions
>> sum(A) %returning a row vector of the
sums of each
Polynomials
column of matrix A
MATLAB plotting
ans=
2-D & 3-D Graphics
4 6
Flow Control
>> rank(A) %to find the rank of matrix A
System analysis
ans=
Curve fitting

Symbolic math.
2
Signal processing

Function m-file >> T= A’ %to find the transpose of matrix


MATLAB Simulink
A
Final Test
TFaculty
= of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Handling Arrays ‘Matrices’


SIMATIC HMI
MATLAB
The Human
>> A = [1 3;5 9];
Programming
Machine Interface >> B = [4 -7;10 0];
Introduction
MATLAB Basics

Vectors & Arrays


>>C= A + B
Math. Functions
C=
Polynomials 5 -4
MATLAB plotting 15 9
2-D & 3-D Graphics >> A * B
Flow Control ans =
System analysis 34 -7
Curve fitting 110 -35
Symbolic math. >> A - B
Signal processing ans =
Function m-file -3 10
MATLAB Simulink -5 9
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Handling Arrays ‘Matrices’


SIMATIC HMI
MATLAB
The Human
>> A / B
Programming
Machine Interface ans =
Introduction
-0.4286 0.2714
MATLAB Basics

Vectors & Arrays


-1.2857 1.0143
Math. Functions >> det(A) ) %to evaluate
Polynomials determinate of matrix A
MATLAB plotting ans =
2-D & 3-D Graphics -6
Flow Control >>inv(A) %to evaluate inverse of
System analysis
matrix A
Curve fitting
ans= -1.5 0.5
Symbolic math. 0.8333 -0.1667
Signal processing Test: How we can find adj(A)?
Function m-file

MATLAB Simulink >>eig(A) %to evaluate Eigen values of


Final Test matrix A
Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Handling Arrays ‘Matrices’


SIMATIC HMI
MATLAB
The Human
Programming
Machine Interface
>> [V,D]= eig(A) %to evaluate Eigen vectors
and diagonal
Introduction
matrix of A
MATLAB Basics

Vectors & Arrays


V=
Math. Functions -0.8863 -0.2992
Polynomials 0.4632 -0.9542
MATLAB plotting D=
2-D & 3-D Graphics -0.5678 0
Flow Control 0 10.5678
System analysis >>A(2 , 2)
Curve fitting ans =
Symbolic math. 9
Signal processing >>A(2 , :)
Function m-file ans =
MATLAB Simulink
5 9
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Handling Arrays ‘Matrices’


SIMATIC HMI
MATLAB
The Human
Programming
Machine Interface >>A(: , 2) >>G=[16 2 3
Introduction ans =3 13
MATLAB Basics
9 5 11 10
Vectors & Arrays
>> A(:,:) 8
Math. Functions

Polynomials
ans = 9 7 6
MATLAB plotting
1 3 12
2-D & 3-D Graphics
5 9 4 14 15
Flow Control
>> A(:) 1];
System analysis
ans = >> G(1:3, :)
Curve fitting
1 ans=16 2 3
Symbolic math. 5 13
Signal processing 3 5 11 10
Function m-file 9 8
MATLAB Simulink 9 7 6
Final Test Faculty of Electronic Engineering 12 Electronics and Automatic Control Engineering
Industrial
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Handling Arrays ‘Matrices’


SIMATIC HMI
MATLAB
The Human
Programming
Machine Interface >> eye(3) >> ones(2,3)
Introduction ans = ans =
MATLAB Basics
1 0 0 1 1 1
Vectors & Arrays
0 1 0 1 1 1
Math. Functions

Polynomials
0 0 1 >> zeros(2)
MATLAB plotting
>> eye(2,3) ans =
2-D & 3-D Graphics
ans = 0 0
Flow Control
1 0 0 0 0
System analysis
0 1 0 >> zeros(1,4)
Curve fitting
>> ones(3) ans =
Symbolic math. ans = 0 0 0 0
Signal processing 1 1 1 >>rand(n)
Function m-file 1 1 1 >>rand(n,m)
MATLAB Simulink 1 1 1 >>randn(n)
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Handling Arrays ‘Matrices’


SIMATIC HMI
MATLAB
The Human
Programming
Machine Interface >> rand(n) >>randn(n)
Introduction >> rand(3) >> randn(3)
MATLAB Basics ans = ans =
Vectors & Arrays
0.8147 0.9134 -0.2050 1.4090
Math. Functions
0.2785 -1.2075
Polynomials
0.9058 0.6324 -0.1241 1.4172
MATLAB plotting
0.5469 0.7172
2-D & 3-D Graphics
0.1270 0.0975 1.4897 0.6715
Flow Control
0.9575 1.6302
System analysis

Curve fitting

Symbolic math.
>>rand(n,m) >> magic(n)
Signal processing
>> rand(2,3) >> magic(4)
Function m-file
ans = ans =
MATLAB Simulink
0.9649 0.9706 16 2 3 13
Final Test 0.4854
Faculty of Electronic Engineering
5 11 10 8
Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Handling Arrays ‘Matrices’


SIMATIC HMI
MATLAB
The Human
>> A = [1 2 3 4; 2 5 3 8; 1 2 2 0; 8 5 3 1];
Programming
Machine Interface >> plot(A) % Linear 2-D plot of
Introduction
matrix A
MATLAB Basics

Vectors & Arrays

Math. Functions

Polynomials

MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Math. Functions
SIMATIC HMI
MATLAB
The Human MATLAB contains all of the standard functions
Programming
Machine Interface
such as sin, cos, log, exp, sqrt, as well as many
Introduction
others.
MATLAB Basics Commonly used constants such as pi, and i or j
Vectors & Arrays
for the square root of -1 (imaginary part), are
Math. Functions also incorporated into MATLAB.
Polynomials

MATLAB plotting

2-D & 3-D Graphics


Ex:
Flow Control
t=0:0.25:10;
System analysis
y = sin(t);
Curve fitting
plot(t,y)
Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Trigonometric Math. Functions


SIMATIC HMI
MATLAB sin sine of argument in radians
The Human
Programming
Machine Interface
sind sine of argument in degrees
cos cosine of argument in radians
Introduction
cosd cosine of argument in degrees
MATLAB Basics
tan tangent of argument in radians
Vectors & Arrays
tand tangent of argument in degrees
Math. Functions

Polynomials asin inverse sine; result in radians


asind inverse sine; result in degrees
MATLAB plotting
acos inverse cosine; result in radians
2-D & 3-D Graphics acosd inverse cosine; result in degrees
Flow Control atan inverse tangent; result in radians
atan2 four-quadrant inverse tangent
System analysis

Curve fitting sinh hyperbolic sine of argument in radians


Symbolic math. asinh inverse hyperbolic sine
Signal processing cosh hyperbolic cosine
acosh inverse hyperbolic cosine
Function m-file
tanh hyperbolic tangent
MATLAB Simulink atanh inverse hyperbolic tangent
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Trigonometric Math. Functions


SIMATIC HMI
MATLAB
The Human
Programming hypot square root of sum of squares
Machine Interface
sec secant of argument in radians
Introduction
secd secant of argument in degrees
MATLAB Basics csc cosecant of argument in radians
Vectors & Arrays cscd cosecant of argument in degrees
Math. Functions cot cotangent of argument in radians
Polynomials
cotd cotangent of argument in degrees

MATLAB plotting
asec inverse secant; result in radians
2-D & 3-D Graphics asecd inverse secant; result in degrees
Flow Control
acsc inverse cosecant; result in radians
acscd inverse cosecant; result in degrees
System analysis
acot inverse cotangent; result in radians
Curve fitting acotd inverse cotangent; result in degrees
Symbolic math.

Signal processing
sech hyperbolic secant
csch hyperbolic cosecant
Function m-file
coth hyperbolic cotangent
MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Math. Functions
SIMATIC HMI
MATLAB
The Human
Exponential functions:
Programming
Machine Interface exp exponential
Introduction log natural logarithm
MATLAB Basics log10 common (base 10) logarithm
Vectors & Arrays
log2 base 2 logarithm and dissect floating-point
numbers into exponent and mantissa
Math. Functions
pow2 base 2 power and scale floating-point numbers
Polynomials sqrt square root
MATLAB plotting

2-D & 3-D Graphics


Complex variable functions:
abs absolute value and complex magnitude
Flow Control
angle phase angle
System analysis complex construct complex data from real and imaginary
Curve fitting components
Symbolic math. conj complex conjugate
i, j imaginary unit
Signal processing
imag imaginary part of complex number
Function m-file real real part of complex number
MATLAB Simulink sign signum function
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Math. Functions
SIMATIC HMI
MATLAB
The Human Rounding and remainder
Programming
Machine Interface round round to nearest integer
Introduction fix round toward zero
MATLAB Basics ceil round toward positive infinity
Vectors & Arrays floor round toward negative infinity
Math. Functions
mod modulus after division
rem remainder after division
Polynomials

MATLAB plotting Math Constants


2-D & 3-D Graphics eps floating-point relative accuracy
Flow Control inf infinity
NaN not-a-number
System analysis
pi ratio of circle's circumference to its diameter, π
Curve fitting i, j imaginary unit
Symbolic math.

Signal processing Note:


Function m-file
there are other much MATLAB functions will
be studied during this course.
MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Polynomials
SIMATIC HMI
MATLAB
The Human In MATLAB, a polynomial is represented by a
Programming
Machine Interface vector. To create a polynomial in MATLAB,
Introduction simply enter each coefficient of the polynomial
MATLAB Basics into the vector in descending order. For
Vectors & Arrays instance:
Math. Functions

Polynomials ,
MATLAB plotting >>p = [1 3 -15 -2 9]
2-D & 3-D Graphics >>f = [1 0 0 0 1]
Flow Control p=
System analysis f=
Curve fitting 1 3 -15 -2 9
Symbolic math.
1 0 0 0 1
Signal processing

Function m-file
>>roots(p) %calculates the roots of a
MATLAB Simulink
polynomial
Final Test
ans =
Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Polynomials
SIMATIC HMI
MATLAB
The Human >> r=[1 2 3];
Programming
Machine Interface
>> P=poly(r) %returns to the polynomial
Introduction
coefficients from roots
MATLAB Basics
P=
Vectors & Arrays

Math. Functions
1 -6 11 -6
Polynomials  to multiply and divid two polynomials
MATLAB plotting together:
2-D & 3-D Graphics >>x = [1 2];
Flow Control >> y = [1 4 8];
System analysis >>z = conv(x,y) %polynomial multiplication
Curve fitting z=
Symbolic math. 1 6 16 16
Signal processing >>[q, r] = deconv(z,y) %polynomial division
Function m-file q=
MATLAB Simulink 1 2
Final Test
r = Engineering
Faculty of Electronic Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Polynomials
SIMATIC HMI  Symbolic
MATLAB
The Human representation of the polynomial
Programming
Machine Interface whose coefficients are in the numeric vector:
Introduction
>>p= poly2sym([1 3 2])
MATLAB Basics
p=
Vectors & Arrays

Math. Functions
x^2 + 3*x + 2
The default symbolic variable is x. The
Polynomials
required variable symbol can be specified as a
MATLAB plotting
second input argument.
2-D & 3-D Graphics
>>f= poly2sym([1 0 1 -1 2], y)
Flow Control
f=
System analysis
y^4 + y^2 - y + 2
Curve fitting To find the value of a polynomial using the
Symbolic math. polyval function. For example, to find the value
Signal processing of the following polynomial at x=2
Function m-file >>f = [1 0 0 0 1];
MATLAB Simulink >>v = polyval(f , 2)
Final Test vElectronic
Faculty of = Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Polynomials
SIMATIC HMI
MATLAB  Polynomial
The Human
Programming
derivative
Machine Interface
Introduction
>>k = polyder(p) %returns the derivative of the
polynomial p.
MATLAB Basics

Vectors & Arrays


>>p = [1 0 -2 -5];
Math. Functions >>q = polyder(p)
Polynomials q=
MATLAB plotting 3 0 -2
2-D & 3-D Graphics

Flow Control k = polyder(a,b) %returns the derivative of the


System analysis product of the
polynomials a and b.
Curve fitting

Symbolic math.
>>a = [3 6 9];
Signal processing >> b = [1 2 0];
Function m-file >>k = polyder( a , b)
MATLAB Simulink k=
Final Test 12
Faculty of Electronic Engineering 36 42 Industrial
18Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Polynomials
SIMATIC HMI  Rational
MATLAB
The Human Polynomial derivative
Programming
Machine Interface
[q,d] = polyder(b,a) %returns the derivative of
Introduction
the rational
MATLAB Basics
polynomial quotient
Vectors & Arrays
b/a.
Math. Functions
>>a = [1 3 5];
Polynomials
>>b = [2 4 6];
MATLAB plotting
>>[n,d] = polyder(a,b)
2-D & 3-D Graphics
n=
Flow Control
-2 -8 -2
System analysis
d=
Curve fitting
4 16 40 48 36
Symbolic math.
partial fraction expansion:
Signal processing

Function m-file
>>[r,p,k] = residue( n,d )
MATLAB Simulink
Where n,d vectors that specify the coefficients of the
Final Test numerator and the denominator,
Faculty of Electronic Engineering
r is the column
Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

Polynomials
SIMATIC HMI
MATLAB
The Human
Programming
>>n = [ 5 3 -2 7];
Machine Interface
>>d = [-4 0 8 3];
Introduction
MATLAB Basics
>>[r, p, k] = residue(n,d);
Vectors & Arrays r=
Math. Functions -1.4167 -0.6653 1.3320
Polynomials p=
MATLAB plotting 1.5737 -1.1644 -0.4093
2-D & 3-D Graphics k=
Flow Control -1.2500
System analysis Note: to convert the partial fraction expansion
Curve fitting back to polynomial coefficients use;
Symbolic math. >>[n,d] = residue(r,p,k)
Signal processing n = -1.2500 -0.7500 0.5000 -1.7500
Function m-file d = 1.0000 -0.0000 -2.0000 -0.7500
MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives

End of Lecture No. “1”


SIMATIC HMI
MATLAB
The Human
Programming
Machine Interface
Introduction
MATLAB Basics

Vectors & Arrays

Math. Functions

Polynomials

MATLAB plotting

2-D & 3-D Graphics

Flow Control

System analysis

Curve fitting

Symbolic math.

Signal processing

Function m-file

MATLAB Simulink

Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering

You might also like