matlab comm2m harry r. erwin, phd university of sunderland

45
MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Post on 21-Dec-2015

231 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

MATLAB

COMM2M

Harry R. Erwin, PhD

University of Sunderland

Page 2: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Resources

• Higham and Higham, 2000, MATLAB Guide, SIAM.

• http://www.utexas.edu/math/Matlab/Manual/faq.html—source of the history presented here.

Page 3: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

MATLAB Introduction (FAQ)

• MATLAB was originally developed to be a "matrix laboratory," written to provide easy access to matrix software developed by the LINPACK and EISPACK projects.

• Since then, the software has evolved into an interactive system and programming language for general scientific and technical computation and visualization.

Page 4: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

SIMULINK (FAQ)• SIMULINK is an interactive system for the nonlinear

simulation of dynamic systems. • A graphical, mouse-driven program that allows systems

to be modeled by drawing a block diagram on the screen.

• It can handle linear, nonlinear, continuous-time, discrete-time, multivariable, and multirate systems.

• SIMULINK runs on workstations using X-Windows. • SIMULINK is fully integrated with MATLAB, and,

together with MATLAB and the Control System Toolbox, forms a complete control system design and analysis environment.

Page 5: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

LAPACK

• A high performance matrix processing library, commonly used in computational science.

• A descendent of LINPACK

• Currently integrated with MATLAB.

Page 6: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

MATLAB History (FAQ)

• In the mid-1970s, Cleve Moler and several colleagues developed the FORTRAN subroutine libraries called LINPACK and EISPACK under a grant from the National Science Foundation.

• LINPACK was a collection of FORTRAN subroutines for solving linear equations, while EISPACK contained subroutines for solving eigenvalue problems.

• Together, LINPACK and EISPACK represented state of the art software for matrix computation.

Page 7: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Second Phase (FAQ)

• In the late 1970s, Moler, who was then chairman of the computer science department at the University of New Mexico, wanted to be able to teach students in his linear algebra courses using the LINPACK and EISPACK software.

• However, he didn't want them to have to program in FORTRAN, because this wasn't the purpose of the course.

• So, as a "hobby" on his own time, he started to write a program that would provide simple interactive access to LINPACK and EISPACK.

Page 8: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Emergence of MATLAB (FAQ)

• Moler named his program MATLAB, for MATrix LABoratory.

• Over the next several years, when he would visit another university to give a talk, or as a visiting professor, he would end up by leaving a copy of his MATLAB on the university machines.

• Within a year or two, MATLAB started to catch on by word of mouth within the applied math community as a "cult" phenomena.

Page 9: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Professional MATLAB Development (FAQ)

• In early 1983, John Little was exposed to MATLAB because of a visit Cleve made to Stanford.

• Little, an engineer, recognized the potential application of MATLAB to engineering applications.

• So in 1983, Little teamed up with Moler and Steve Bangert to develop a second generation, professional version of MATLAB written in C and integrated with graphics.

• The MathWorks, Inc. was founded in 1984 to market and continue development of MATLAB.

Page 10: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Basic Features of MATLAB (FAQ)

• MATLAB commands are expressed in a form very similar to that used in mathematics and engineering. – For instance, b = A x, where A, b, and x are matrices, is

written b = A * x .

– To solve for x in terms of A and b, write x = A\b

• There is no need to program matrix operations explicitly like multiplication or inversion.

• Solving problems in MATLAB is much quicker than programming in a high-level language such as C or FORTRAN.

Page 11: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Character Set

• ASCII Character Set

• The following are used as operators:– ! ‘ “ ( : ) , … / : ; < <= == > >= @ [..] [] % & \ ^

| >> ~ ~=– .’ .* ./ .\ .^

Page 12: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Comments

• A line beginning with %

Page 13: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Variable Names

• Case sensitive• Up to 31 characters long• Begin with a letter• Followed by letters, digits, underscores• Variables are created when they are assigned.• pi, i, and j are predefined.• To list variables use who or whos (detailed)• clear or clear var clears out the workspace

Page 14: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Commands

• Type exit or quit to quit MATLAB• Type foo to run foo.m• Terminate a command with ; to suppress output• A continuation line is shown with …• clc clears the command window• help foo displays the help for foo()• lookfor will search for a string in the help• ^C to abort a command

Page 15: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

More Commands

• To save the current workspace to filename.mat: save filename

• To load: load filename

• To capture output: diary filename and diary off or diary on

• To display a variable: disp var

• To interact with the operating system: !

Page 16: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Data Types

• Originally just complex matrices• Now include

– double– sparse (2-D only)– char– cell– struct– storage (specialized)– function handle

• The fundamental types are multi-dimensional arrays

Page 17: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Matrices and Arrays

• A(i,j,k) accesses that entry in the matrix A

• More next week

Page 18: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Operators 1

• ! System command• ‘ Conjugate transpose, string delimiter• “ Quote• ( : ) Used in matrix subscripting• , Separates commands• … Continuation• / Right division• : Colon• ; Terminates a command without output

Page 19: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Operators 2

• < Less than• <= Less than or equal• == Logical equal• > Greater than• >= Greater than or equal• @ Function handle• [..] Matrix building• [] Empty matrix• % Comment• & Logical and

Page 20: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Operators 3

• \ Left division• ^ Power• | Logical or• >> Prompt• ~ Logical not• ~= Logical not equal• * Multiplication• + Addition• - Subtraction

Page 21: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Array Operators

• .’ Transpose

• .* Array multiplication

• ./ Array right division

• .\ Array left division

• .^ Array exponentiation

• inv(A) Inverse

Page 22: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

IEEE Arithmetic

• All arithmetic is in accordance with the double precision IEEE standard.

• 64 bits per number

• All computations are in floating point.

• You can get NaNs if the computations are undefined.

Page 23: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Statements

• Multiple statements can appear on the same line, separated by semicolons or commas.

• If a statement is terminated by a semicolon, output is suppressed; otherwise it is printed.

• Output can be formatted with the format command

Page 24: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Functions

• MATLAB has thousands of functions, and you can add your own using m-files.

Page 25: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Function Argument Lists• Input arguments are to the right of the function name, within

parentheses• Output arguments are to the left of the function name,

within square brackets– X = [3 4];– norm(X)ans = 5– norm(X,1)ans = 7– [m,n] = size(A)m = 5n = 3

Page 26: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

M-Files

• Sample file%MARKS

Exmark = [12 0 5 28 87 3 56];

Exsort = sort(Exmark)

Exmean = mean(Exmark)

Exmed = median(Exmark)

Exstd = std(Exmark)

Page 27: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Storage Allocation

• Automatic, as necessary, and with garbage collection (notorious for memory leaks).

• Array dimensions are expanded automatically as needed to make assignments sensible.

Page 28: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Control System Toolbox

• This is a toolbox for control system design and analysis. It supports transfer function and state-space forms (continuous/discrete time, frequency domain), as well as functions for step, impulse, and arbitrary input responses. Functions for Bode, Nyquist, Nichols plots, design with root-locus, pole-placement, and LQR optimal control are also included.

Page 29: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Image Processing Toolbox

• The Image Processing Toolbox builds on MATLAB's numeric, signal processing, and visualization capabilities to provide a comprehensive system for image processing and algorithm development.

• Heavily used here.

Page 30: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

MMLE3 Identification Toolbox

• The MMLE3 Identification Toolbox is a specialized toolbox for use with MATLAB and the Control System Toolbox for the estimation of continuous-time state-space models from observed input-output data.

Page 31: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Model Predictive Control Toolbox

• The Model Predictive Control Toolbox is especially useful for applications involving constraints on the manipulated and/or controlled variables. For unconstrained problems, model predictive control is closely related to linear quadratic optimal control, but includes modeling and tuning options that simplify the design procedure.

Page 32: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Mu-Analysis and Synthesis Toolbox

• The Mu-Analysis and Synthesis Toolbox contains specialized tools for the analysis and design of robust, linear control systems, extending MATLAB to provide additional application-specific capabilities.

Page 33: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Nonlinear Control Design

• This toolbox provides a Graphical User Interface to assist in time-domain-based control design. With this toolbox, you can tune parameters within a nonlinear SIMULINK model to meet time-domain performance requirements. You can view the progress of an optimization while it is running. Optimization routines have been taken from the Optimization Toolbox.

Page 34: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Neural Network Toolbox

• This is a toolbox for designing and simulating neural networks and supports implementation of the perceptron learning rule, the Widrow-Hoff rule, and several variations of the backpropagation rule. Transfer functions included are hard limit, linear, logistic, and hypertangent sigmoid.

• This will be the toolbox you use most here.

Page 35: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Optimization Toolbox

• This is a toolbox for linear and nonlinear optimization. It supports unconstrained and constrained minimization, minimax, nonlinear least squares, multi-objective, semi-infinite optimization, linear programming, quadratic programming, and the solution of nonlinear equations.

Page 36: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Robust Control Toolbox

• This is a toolbox for robust control system design and supports LQG/loop transfer recovery, H2, H0, and mu- control synthesis, singular value frequency response, and model reduction.

Page 37: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Signal Processing Toolbox

• This is a toolbox for digital signal processing (time series analysis). It includes functions for the design and analysis of digital filters, like Butterworth, Elliptic, and Parks-McClellan, and for FFT analysis (power spectrum estimation). It also includes some two-dimensional signal processing capabilities.

• Very popular in the acoustics field.

Page 38: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Spline Toolbox

• This is a toolbox for working with splines and is typically used for curve fitting, solution of function equations, and functional approximation.

Page 39: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Statistics Toolbox

• The Statistics Toolbox builds on the computational and graphics capabilities of MATLAB to provide: 1) statistical data analysis, modeling, and Monte Carlo simulation 2) building blocks for creating your own special-purpose statistical tools, and 3) GUI tools for exploring fundamental concepts in statistics and probability.

Page 40: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Symbolic Math Toolbox

• The Symbolic Math Toolbox contains functions for symbolic algebra, exact linear algebra, variable precision arithmetic, equation solving, and special mathematical functions. Its underlying computational engine is the kernel of Maple. The Extended Symbolic Math Toolbox augments the functionality to include Maple programming features and specialized libraries.

Page 41: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

System Identification Toolbox

• This is a toolbox for parametric modeling. Identified models are in transfer function form (either z transform or Laplace transform) and state-space form (e.g., ARMA models or Box-Jenkins models).

Page 42: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Chemometrics Toolbox

• This toolbox contains a library of functions that allows you to analyze data based on chemometrics methods including multiple linear regression, classical least squares, inverse least squares, Q-matrix, factor based methods, principle component regression, and partial least squares in latent variables. There are also useful functions for plotting data.

Page 43: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Frequency Domain System Identification Toolbox

• This toolbox contains tools for accurate modeling of linear systems with or without delay. The models are transfer functions in s-domain or in z-domain. The procedures include excitation signal design, data preprocessing, parameter estimation, graphical presentation of results, and model validation (tests, uncertainty bounds, modelling errors).

Page 44: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Hi-Spec™Toolbox

• The Hi-Spec [tm ] Toolbox, a Partner Series Toolbox, was created by Jerry Mendel, C.L. (Max) Nikias, and Ananthram Swami. The Hi-Spec Toolbox is a collection of MATLAB routines whose primary features are functions for:– Higher-order spectrum estimation either by conventional

or parametric approaches– Magnitude and phase retrieval– Adaptive linear prediction– Harmonic retrieval and quadratic phase coupling – Time-delay estimation and array signal processing

Page 45: MATLAB COMM2M Harry R. Erwin, PhD University of Sunderland

Tutorial Exercises

• Work through the brief tutorial if you have the text.