MATLAB Programming Lecture 5
MATLAB Programming Lecture 5
Lecture No.“5”
SIMATIC HMI
MATLAB
The Human
Programming
Machine Interface
Introduction
MATLAB
MATLAB Basics
Math. Functions
Polynomials
MATLAB plotting
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
Curve fitting
SIMATIC HMI
MATLAB You have some data and you want to find
The Human
Programming
Machine Interface the accurate relation that fits these data.
Introduction In many curve fitting applications, the
MATLAB Basics
objective is to estimate the coefficients of
Vectors & Arrays
a n-order polynomial. The polynomial is
Math. Functions
then used as a model for observed noisy
Polynomials
data. For example, if a quadratic
MATLAB plotting
polynomial is to be used, there are three
2-D & 3-D Graphics
coefficients (a, bthat
The polynomial and fits
c) to estimate:
best is defined as
Flow Control a x2 + b x + c =0the sum of the
the one that minimizes
System analysis
squared errors between itself and the
Curve fitting
noisy data.
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
Curve fitting
SIMATIC HMI Measuring the concentration of a
MATLAB
The Human
Programming
Machine Interface
Experimentcompound in blood samples taken
Introduction
from several subjects at various
MATLAB Basics times after taking an
experimental medication.
Vectors & Arrays
time = [ 0.1 0.1 0.3 0.3 1.3 1.7 2.1
Math. Functions
Polynomials
2.6 3.9 3.9 5.1 5.6
MATLAB plotting
6.2 6.4 7.7 8.1 8.2 8.9 9.0
2-D & 3-D Graphics
9.5 9.6 10.2 10.3 10.8
Flow Control
11.2 11.2 11.2 11.7 12.1
System analysis 12.3 12.3 13.1 13.2 13.4
Curve fitting 13.7 14.0 14.3 15.4 16.1
Symbolic math. 16.1 16.4 16.4 16.7 16.7
Signal processing 17.5 17.6 18.1 18.5 19.3
Function m-file
19.7];
MATLAB Simulink
conc = [0.01 0.08 0.13 0.16 0.55
Final Test
0.90 1.11 1.62 1.79
Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives
Curve fitting
SIMATIC HMI
MATLAB plot(time,conc,'o')
The Human
Programming
Machine Interface xlabel('Time')
Introduction ylabel('Blood Concentration')
MATLAB Basics
Math. Functions
Polynomials
MATLAB plotting
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
Polynomial Curve
>>p = polyfit(x,y,n) Fitting
% finds the
SIMATIC HMI
MATLAB
coefficients of an n –degree
The Human
Programming
Machine Interface polynomial p
Introduction that fits a set of data (x ,y)
MATLAB Basics Example:
Vectors & Arrays >>x = [1 2 3 4 5];
Math. Functions >>y = [5.5 43.1 128 290.7 498.4];
Polynomials >>p = polyfit(x,y,3)
MATLAB plotting >> pyi== polyval(p,xi) %returns the
2-D & 3-D Graphics
value(s)-0.1917 31.5821 -60.3262
yi of an n-degree
Flow Control
35.3400 polynomial p
System analysis
evaluated at value(s) xi
Example:
Curve fitting
>> yi = polyval(p,7.5)
Symbolic math.
yi =
Signal processing
1.2785e+003
Function m-file
Note: Each value of the vector yi represents
MATLAB Simulink
the corresponding
Final Test Faculty of Electronicsubstitution
Engineering with values of vector
Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives
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
Analyzing residuals
SIMATIC HMI
MATLAB Example:
The Human Residuals :represent the difference
Programming
Machine Interface clear all , close all , clc
between the real data and the estimated
Introduction x=[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7
MATLAB Basics data0.9
0.8 that1];used to measure goodness of
Vectors & Arrays
y=[-2.1 -1.12 0.9 fitting.
1.44 2.1 2.4 2.77
Math. Functions
3.6 4.1 4.66 4.9];
Polynomials p1=polyfit(x,y,1) % polynomial of
MATLAB plotting degree 1
2-D & 3-D Graphics p2=polyfit(x,y,4) % polynomial of
Flow Control degree 4
System analysis
Math. Functions
Polynomials
MATLAB plotting
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
MATLAB plotting
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
Polynomials
MATLAB plotting
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
Polynomials
MATLAB plotting
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
Polynomials
MATLAB plotting
Symbolic
Polynomial
2-D & 3-D Graphics
expression
P=[1 1 2]
Flow Control
f=x^2+x+2
System analysis
Example: Example:
Curve fitting >>syms x >>syms x
Symbolic math.
>>p=[1 1 >>f = x^2 + x
Signal processing
2]; + 2;
Function m-file >>f=poly2sym >>p=sym2poly
MATLAB Simulink (p) (f )
Final Test Faculty off=
Electronic Engineering Industrial Electronicsp=
and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives
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
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives
Math. Functions
Polynomials
MATLAB plotting
Flow Control
Math. Functions
Polynomials
MATLAB plotting
Math. Functions
Polynomials
MATLAB plotting
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
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
Signal processing
>>z=t;
>>ezplot3(x,y,z,[0, 6*pi])
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
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives
Curve fitting
>> solve(eq1, eq2, ..., eqn) %solves the
Symbolic math. system of equations
Signal processing
Function m-file
eq1,eq2,...,eqn in the n variables
MATLAB Simulink
Final Test
determined by syms vars.
Industrial Electronics and Automatic Control Engineering
Faculty of Electronic Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives
Curve fitting
clear all ,clc
Symbolic math.
syms n p q d
Signal processing e1='d^2+(n+p)/2=q';
Function m-file e2='p=n+d+q-10';
MATLAB Simulink e3='q+d=p+n/4';
Final Test e4='q+p=n+8*d-1';
Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives
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
Integral Transforms
SIMATIC HMI
MATLAB
The Human
Programming
Machine Interface
t-domain
Laplace transform: s-domain
Introduction
MATLAB Basics
Integral Transforms
SIMATIC HMI
MATLAB
The Human
Programming
Machine Interface
t-domain
Fourier transform: ω -domain
Introduction
MATLAB Basics
Integral Transforms
SIMATIC HMI
MATLAB
Z- transform: F(z)
The Human
Programming
Machine Interface f(n)
Introduction
MATLAB Basics
Math. Functions
Polynomials
>> F = ztrans (f) %Finds Z-
MATLAB plotting
transform
2-D & 3-D Graphics
>> f = iztrans (F) %Finds
Flow Control
Example1:
inverse Z-transform Example2:
System analysis >>syms n >>syms z
Curve fitting >>f = n^4; >>f = 2*z/(z-
Symbolic math. >>F=ztrans(f) 2)^2;
Signal processing F= >>F=iztrans(f)
Function m-file
(z^4 + 11*z^3 + F=
11*z^2 + z)/(z - 1)^5 2^n +
MATLAB Simulink
2^n*(n - 1)
Final Test Faculty of Electronic Engineering Industrial Electronics and Automatic Control Engineering
for internal use only Automation
Dr./ Essam and
Nabil
Drives
Math. Functions
Polynomials
MATLAB plotting
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