Introduction to MATLAB - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Introduction to MATLAB

Description:

Create matrices for 'xg yg' grid [xg, yg] = meshgrid(x,y) ... for element by element multiplication where xg and yg are 20x20 matricies) ... – PowerPoint PPT presentation

Number of Views:51
Avg rating:3.0/5.0
Slides: 12
Provided by: marvin96
Category:

less

Transcript and Presenter's Notes

Title: Introduction to MATLAB


1
Introduction to MATLAB
  • Notes to complement on-line demo

2
MATLAB Overview
  • What is MATLAB
  • A program that may be used to automate
    mathematical computations
  • Interpretive environment, calculations at the
    command line
  • Includes scripting language, you can write
    programs
  • Rich with engineering oriented functions
  • Modern engineering tool widely used in
    engineering
  • Includes Toolboxes for specialty applications
  • Controls
  • Signal Processing
  • Bio-system simulation
  • Includes block diagram based simulation
    Simulink

3
Simple Calculations
  • Command Line Interpreter
  • Set variables
  • A3
  • B3,4,7 row vector
  • C3 4 7 column vector
  • D1,23,4 matrix
  • Show variables
  • Who,whos
  • Clear variables
  • Clear, clear x
  • Set iterated list
  • E10.210 (start increment end)

4
Getting help
  • Best
  • Select Help from the menu (MATLAB 6)
  • Next Best (UNIX/LINUX)
  • Use the command HELP from the command prompt
  • HELP Alone for general list topic areas
  • Help topic for help on topic
  • Topics are divided into general areas
  • Controls, Signal processing, etc.
  • Local functions may be added to the local dir
  • Organized with
  • General help
  • Toolbox help

5
Complex Numbers
  • Set number
  • A3 4i
  • Magnitude
  • Mabs(A)
  • Angle
  • Alphaangle(A)
  • Conjugate
  • A_starconj(A)
  • Imaginary part / real part
  • Imag_a imag(A)
  • Real_areal(A)
  • Try sqrt(-1)

6
Simple Plotting
  • Simple x/y plot
  • x0120
  • xsin(x)
  • plot(x,y)
  • Set line /point type
  • plot(x,y,c) cyan points
  • plot(x,y,c,x,y,y-) cyan points and yellow
    line
  • Set Titles and labels Labels
  • xlabel(X-axis), Ylabel(Y-Axis)
  • Title(Title)
  • Alternative Use figure menu /Edit/Axis
    Properties
  • Set axis titles
  • Main title
  • Line properties etc.

7
3D plot
  • Set x and y values
  • x 0.120
  • y 0.120
  • Create matrices for xg yg grid
  • xg, yg meshgrid(x,y)
  • Calculate an equation for z on the grid
  • z sin(pixg/20). sin(piyg/20)
  • (note the . for element by element
    multiplication where xg and yg are 20x20
    matricies)
  • Plot the surface or mesh
  • surf(x,y,z) or mesh(x,y,z)

8
Matrix math
  • Consider a set of equations
  • Given x1,x2 you can find y1,y2.
  • The more usual problem is y1,y2 are given and you
    need x1,x2
  • Solution
  • Write in matrix form and solve

9
Matrix math
  • Example
  • Set y,A
  • Y 3 4
  • A 7 , 4.5 3.3, 9.1
  • Find A inverse (A-1)
  • Ai inv(A)
  • Calculate x
  • x Aiy

10
Additional matrix operations
  • Transpose a matrix
  • (switch rows and columns)
  • y y
  • To multiply element by element by a scalar
  • y sin(y) . y (replace each element by y sin
    y)

11
M-File -programs
  • Use File menu to create or open a script file
  • Use Matlab commands as script
  • Save into m-file space and then execute by file
    name on the command line
  • Example
  • Save as sin_surf.m
  • Execute as sin_surf on the command line

for i 130 for j 130 z(i,j)
sin(3.14159 ((i - 16) 2 (j - 16) 2) / (7
30)) ( j - 1) end end surfc(z)
Write a Comment
User Comments (0)
About PowerShow.com