An Introduction to MATLAB Lesson 1 - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

An Introduction to MATLAB Lesson 1

Description:

Space or comma are used to separate elements in the same row. The square braces are ... matrix with elements 3.5 , 6.3 and 33. Commas or space are used to separate the ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 22
Provided by: Fadh4
Category:

less

Transcript and Presenter's Notes

Title: An Introduction to MATLAB Lesson 1


1
An Introduction to MATLABLesson 1
  • Presenter Andreas Zollmann
  • Most of this stuff stolen from
  • Dr. Samir Al-Amer

2
MATLAB
  • MATLABMATrix LABratory
  • It is widely used to solve different types of
    scientific problems.
  • The basic data structure is a complex double
    precision matrix.

3
MATLAB AS A CALCULATOR
Command window
gtgt 394.45 ans 176.6000
Command window
4
MATLAB Assignment
  • Variable names
  • Starts with a letter
  • Up to 31 characters ( some use 19 or 21)
  • May contain letters, digits and underscore_
  • Case sensitive (A is not the same as a)
  • A2.3
  • A
  • 2.3000

5
Scalar Assignment
The square braces are used to define
matrices. We can use them for scalars too.
  • A2.3
  • A
  • 2.3000

6
Row vector
X2,3 7
X 2 3 7
7
Column vector
X23 7
X 2 3 7
8
MATLAB Statements
9
MATLAB Math Assignment Operators 
  • Power  or . ab or   a.b
  • Multiplication   or . ab or a.b
  • Division / or ./ a/b or a./b
  •      or \ or .\ b\a or b.\a
  •    NOTE         56/8 8\56 
  • - (unary)  (unary)
  • Addition      a b
  • Subtraction -       a - b
  • Assignment    a b     (assign b to a)

10
MATLAB Statements
11
Help
  • A good idea is use the help
  • help provides information about the available
    functions and how to use them.
  • Try
  • help eig
  • help inv
  • help roots

12
Programming in MATLAB
  • There are two types of MATLAB programs

script files
function files
script file P1 3 2 roots(P)
function yfun(x) yx23x22
13
Programming in MATLABScript files
  • A Script file contains a set of MATLAB command
  • Use them when you have a long sequence of
    statements to solve a problem
  • Can run the program by typing its name in the
    command window or from tools in the editor
    window.

14
Relational Operators
15
Logical Operators
if (Xgt6) (xlt3)
16
Caution! These operators work element-wise
  • if A B, statement, end
  • does not work as intended!
  • ? instead use
  • if any(any(A B)), statement, end
  • any true iff any element of vector is nonzero
  • all true iff all elements of vector are nonzero

17
More useful functions
  • All of form f(A,dim) by default act on rows
  • ones, zeros, max, min, mean, median, sum, prod,
    sort

18
If structures
  • General form
  • If condition
  • statements
  • else
  • statements
  • end

If (xgt0) sign1 elseif (x0)
sign0 else sign-1 end
19
for loops
  • General form
  • for indexinitial increment limit
  • statements
  • end

s0 for i1311 ssi end
20
Other cool commands
  • A textread('a.txt','n')
  • read file containing numbers into vector A
  • plot(1n_o_iterations,thetas)
  • ezplot('sin(x)',0,10)
  • ezplot(sprintf('g(exp(-x/g)-exp(-x/g))',1/(the
    ta1-theta2),theta1,theta2),0,400)
  • fh _at_(x,y) (x2y2)
  • ezsurfc(fh,0 1)

21
Documentation
  • Nice easy-to-read introduction
  • http//www.andrew.cmu.edu/course/16-720/extras/pr
    imer.pdf
  • More stuffhttp//www.mathworks.com/academia/stud
    ent_center/tutorials/launchpad.html
Write a Comment
User Comments (0)
About PowerShow.com