Matlab 1

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

Transcript of Matlab 1

Page 1: Matlab 1

MATLAB

COMM2MHarry R. Erwin, PhD

University of Sunderland

Page 2: Matlab 1

Resources

• Higham and Higham, 2000, MATLABGuide, SIAM.

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

Page 3: Matlab 1

MATLAB Introduction (FAQ)

• MATLAB was originally developed to be a"matrix laboratory," written to provide easyaccess to matrix software developed by theLINPACK and EISPACK projects.

• Since then, the software has evolved intoan interactive system and programminglanguage for general scientific andtechnical computation and visualization.

Page 4: Matlab 1

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 onthe 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 SystemToolbox, forms a complete control system design andanalysis environment.

Page 5: Matlab 1

LAPACK

• A high performance matrix processinglibrary, commonly used in computationalscience.

• A descendent of LINPACK• Currently integrated with MATLAB.

Page 6: Matlab 1

MATLAB History (FAQ)

• In the mid-1970s, Cleve Moler and severalcolleagues developed the FORTRAN subroutinelibraries called LINPACK and EISPACK under agrant from the National Science Foundation.

• LINPACK was a collection of FORTRANsubroutines for solving linear equations, whileEISPACK contained subroutines for solvingeigenvalue problems.

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

Page 7: Matlab 1

Second Phase (FAQ)

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

• However, he didn't want them to have to programin FORTRAN, because this wasn't the purpose ofthe course.

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

Page 8: Matlab 1

Emergence of MATLAB (FAQ)

• Moler named his program MATLAB, forMATrix LABoratory.

• Over the next several years, when he would visitanother university to give a talk, or as a visitingprofessor, he would end up by leaving a copy ofhis MATLAB on the university machines.

• Within a year or two, MATLAB started to catchon by word of mouth within the applied mathcommunity as a "cult" phenomena.

Page 9: Matlab 1

Professional MATLABDevelopment (FAQ)

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

• Little, an engineer, recognized the potentialapplication of MATLAB to engineeringapplications.

• So in 1983, Little teamed up with Moler and SteveBangert to develop a second generation, professionalversion of MATLAB written in C and integratedwith graphics.

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

Page 10: Matlab 1

Basic Features of MATLAB(FAQ)

• MATLAB commands are expressed in a form verysimilar 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 operationsexplicitly like multiplication or inversion.

• Solving problems in MATLAB is much quicker thanprogramming in a high-level language such as C orFORTRAN.

Page 11: Matlab 1

Character Set

• ASCII Character Set• The following are used as operators:

– ! ‘ “ ( : ) , … / : ; < <= == > >= @ [..] [] % & \^ | >> ~ ~=

– .’ .* ./ .\ .^

Page 12: Matlab 1

Comments

• A line beginning with %

Page 13: Matlab 1

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 1

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 1

More Commands

• To save the current workspace tofilename.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 1

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 1

Matrices and Arrays

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

Page 18: Matlab 1

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 1

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 1

Operators 3

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

Page 21: Matlab 1

Array Operators

• .’ Transpose• .* Array multiplication• ./ Array right division• .\ Array left division• .^ Array exponentiation• inv(A) Inverse

Page 22: Matlab 1

IEEE Arithmetic

• All arithmetic is in accordance with thedouble 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 1

Statements

• Multiple statements can appear on the sameline, 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 formatcommand

Page 24: Matlab 1

Functions

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

Page 25: Matlab 1

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 1

M-Files

• Sample file%MARKSExmark = [12 0 5 28 87 3 56];Exsort = sort(Exmark)Exmean = mean(Exmark)Exmed = median(Exmark)Exstd = std(Exmark)

Page 27: Matlab 1

Storage Allocation

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

• Array dimensions are expandedautomatically as needed to makeassignments sensible.

Page 28: Matlab 1

Control System Toolbox

• This is a toolbox for control system designand analysis. It supports transfer functionand state-space forms (continuous/discretetime, frequency domain), as well asfunctions for step, impulse, and arbitraryinput responses. Functions for Bode,Nyquist, Nichols plots, design with root-locus, pole-placement, and LQR optimalcontrol are also included.

Page 29: Matlab 1

Image Processing Toolbox

• The Image Processing Toolbox builds onMATLAB's numeric, signal processing,and visualization capabilities to provide acomprehensive system for imageprocessing and algorithm development.

• Heavily used here.

Page 30: Matlab 1

MMLE3 Identification Toolbox

• The MMLE3 Identification Toolbox is aspecialized toolbox for use with MATLABand the Control System Toolbox for theestimation of continuous-time state-spacemodels from observed input-output data.

Page 31: Matlab 1

Model Predictive ControlToolbox

• The Model Predictive Control Toolbox isespecially useful for applications involvingconstraints on the manipulated and/orcontrolled variables. For unconstrainedproblems, model predictive control isclosely related to linear quadratic optimalcontrol, but includes modeling and tuningoptions that simplify the design procedure.

Page 32: Matlab 1

Mu-Analysis and SynthesisToolbox

• The Mu-Analysis and Synthesis Toolboxcontains specialized tools for the analysisand design of robust, linear controlsystems, extending MATLAB to provideadditional application-specific capabilities.

Page 33: Matlab 1

Nonlinear Control Design

• This toolbox provides a Graphical UserInterface to assist in time-domain-basedcontrol design. With this toolbox, you cantune parameters within a nonlinearSIMULINK model to meet time-domainperformance requirements. You can viewthe progress of an optimization while it isrunning. Optimization routines have beentaken from the Optimization Toolbox.

Page 34: Matlab 1

Neural Network Toolbox

• This is a toolbox for designing andsimulating neural networks and supportsimplementation of the perceptron learningrule, the Widrow-Hoff rule, and severalvariations 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 1

Optimization Toolbox

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

Page 36: Matlab 1

Robust Control Toolbox

• This is a toolbox for robust control systemdesign and supports LQG/loop transferrecovery, H2, H0, and mu- controlsynthesis, singular value frequencyresponse, and model reduction.

Page 37: Matlab 1

Signal Processing Toolbox

• This is a toolbox for digital signal processing(time series analysis). It includes functions for thedesign and analysis of digital filters, likeButterworth, Elliptic, and Parks-McClellan, andfor FFT analysis (power spectrum estimation). Italso includes some two-dimensional signalprocessing capabilities.

• Very popular in the acoustics field.

Page 38: Matlab 1

Spline Toolbox

• This is a toolbox for working with splinesand is typically used for curve fitting,solution of function equations, andfunctional approximation.

Page 39: Matlab 1

Statistics Toolbox

• The Statistics Toolbox builds on thecomputational and graphics capabilities ofMATLAB to provide: 1) statistical dataanalysis, modeling, and Monte Carlosimulation 2) building blocks for creatingyour own special-purpose statistical tools,and 3) GUI tools for exploring fundamentalconcepts in statistics and probability.

Page 40: Matlab 1

Symbolic Math Toolbox

• The Symbolic Math Toolbox containsfunctions for symbolic algebra, exact linearalgebra, variable precision arithmetic,equation solving, and special mathematicalfunctions. Its underlying computationalengine is the kernel of Maple. TheExtended Symbolic Math Toolboxaugments the functionality to includeMaple programming features andspecialized libraries.

Page 41: Matlab 1

System Identification Toolbox

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

Page 42: Matlab 1

Chemometrics Toolbox

• This toolbox contains a library of functionsthat allows you to analyze data based onchemometrics methods including multiplelinear regression, classical least squares,inverse least squares, Q-matrix, factorbased methods, principle componentregression, and partial least squares inlatent variables. There are also usefulfunctions for plotting data.

Page 43: Matlab 1

Frequency Domain SystemIdentification Toolbox

• This toolbox contains tools for accuratemodeling of linear systems with or withoutdelay. The models are transfer functions ins-domain or in z-domain. The proceduresinclude excitation signal design, datapreprocessing, parameter estimation,graphical presentation of results, and modelvalidation (tests, uncertainty bounds,modelling errors).

Page 44: Matlab 1

Hi-Spec™Toolbox

• The Hi-Spec [tm ] Toolbox, a Partner SeriesToolbox, was created by Jerry Mendel, C.L.(Max) Nikias, and Ananthram Swami. The Hi-Spec Toolbox is a collection of MATLABroutines 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 1

Tutorial Exercises

• Work through the brief tutorial if you havethe text.