Presentation is loading. Please wait.

Presentation is loading. Please wait.

MATH 493 Introduction to MATLAB

Similar presentations


Presentation on theme: "MATH 493 Introduction to MATLAB"— Presentation transcript:

1 MATH 493 Introduction to MATLAB

2 MATLAB MATLAB is run as an interactive program
You type a command, MATLAB responds with an answer; repeat MATLAB processing is based largely on array and matrix manipulations

3 MATLAB Interface

4 Basic Usage Enter simple calculations at the command prompt
Define variables at the command prompt Use cursor keys to revisit previous commands Use first letters and cursor keys for more control

5 Editor Use File/New/Blank M-file to create a script file
store a sequence of commands for later use editor does automatic highlighting necessary for anything more than toy examples

6 Further Commands Standard mathematical functions are built in:
cos, sin, log, log10, exp Suppress output with semi-colon User variable names should be different from built-in functions, variables File/Clear Workspace (or type ‘clear’) to clear all variables

7 Matrices and MATLAB (Nearly) all MATLAB variables are matrices
scalars are 1x1 matrices vectors are 1xn or nx1 matrices ‘size’ function gives dimensions of a matrix

8 Manually Creating Matrices
Use square brackets v = [1 3 10] Semi-colons separate rows v = [1; 3; 10] Sometimes easier to write using matrix transpose, ’. Compare v = [1 3 10]’

9 Functions for Creating Matrices 1
Colon operator 1:5 - same as [ ] 1:0.1:2 - counts by 0.1 from 1 to 2 linspace linspace(10,50, 1000) - counts from 10 to 50 using 1000 points linspace(10,50) - counts from 10 to 50 using (default) 100 points. Often used for quick graphs

10 Functions for Creating Matrices 2
ones ones(3) - creates 3x3 matrix of ones ones(4,1) - creates 4x1 vector of ones zeros zeros(3) - creates 3x3 matrix of zeros zeros(4,5) - creates 4x5 matrix of zeros eye - (for “Identity”) eye(3) - creates 3x3 identity matrix

11 This is not C Many MATLAB functions can take in single arguments or matrices Using a matrix is often faster and more clear Plotting example - graph of cosine x = linspace(0, 6*pi) y = cos(x) plot(x, y)

12 Plot Command Requirements
‘plot’ will generate an x vs y plot when given two equal-length vectors The plot will appear in a new window There are many plotting options; some are included in the activities

13 Matrix Problems! Try the following plot of a quadratic
x = linspace(-2, 2) y = x^2 plot(x, y) Very common problem in course! x^2 means…. x.^2 means….

14 Continuing Try the exercises on the sheet.
Look at the output each time to make sure you understand what each command is doing!


Download ppt "MATH 493 Introduction to MATLAB"

Similar presentations


Ads by Google