What is MATLAB l An interactive numerical computing environment l Matrix computations l Graphics l Programming (M-files) l Toolboxes (signal processing, statistics, optimization, symbolic math)
Advantage of MATLAB l Easy, interactive environment l Fast numerical algorithms l Inexpensive software l Fun and easy environment for learning Linear Algebra!!
Think Linear Algebra!! l More important and calculus!! l Background Knowledge Given two matrices, A and B, is AB = BA? A and B are symmetric Matrices, is AB symmetric? What is positive definite matrix? What is Eigenvalue decomposition?
Windows Environment MATLAB is essentially operating system independent
Input/Output l MATLAB handles double, char and logical data types l Array need not dimensioned l Variables are case sensitive l Output format can be controlled l Command history remembered
Files MATLAB Handle l M-files (*.m) are script and function files l Mat-files (*.mat) are created by MATLAB with save, and read with load l Mex-files (*.mex) MATLAB callable codes compiled from other languages
General Commands l On-line helps (help, helpwin, helpdesk, lookfor, demo) l Workspace (who, whos, what, clear, clc, clf) l Directory (pwd, cd, dir, ls, path) l General (computer, clock, date, more, ver) l Termination (^c, quit, exit)
Lesson 1 l Assign values to variables l Basic arithmetic (+,-, *, /, ^) l Suppress screen output by ; l Float-point number appearance l Function sin, cos, log l Quit
Lesson 2 l Create row and column vectors l Linearly spaced vectors l Arithmetic on vectors l Array operations with.*,./,.^ l Math functions on vectors
Lesson 3: Creating and Printing Plot l Create points l 2D plots l Printing
Lesson 4: Script file l Create, write, save a script file l How to execute the script file l path, and addpath command l pwd and cd command
Lesson 5: Creating a function l Function file l Executing a function
Exercises l Lesson 3, exercise 3. An exponentially decaying sine plot: Plot y = exp(-0.4x) sin x, 0<x<4
Exercises l Lesson 5, exercise 2. Convert temperature: write a function that outputs a conversion table from Celsius and Fahrenheit temperatures. The two temperatures are related as F = (9/5) C + 32
Exercises l Best way to skin a cat!! l Given a vector x Find the sum Find the sum of squares
Exercise l Monte Carlo Sampling Generate N samples of the sum of M independent uniformly distributed random variables.