Matlab Tutorial - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

Matlab Tutorial

Description:

Matlab Tutorial By Nouman Zubair ... – PowerPoint PPT presentation

Number of Views:179
Avg rating:3.0/5.0
Slides: 27
Provided by: edup1150
Category:
Tags: matlab | tutorial

less

Transcript and Presenter's Notes

Title: Matlab Tutorial


1
Matlab Tutorial
  • By Nouman Zubair

2
Outline
  • Introduction to Matlab
  • Matlab (matrices and arrays)
  • Working with Matlab

3
About Matlab
  • The name Matlab stands for matrix laboratory.
  • Matlab is a high level (matrix/array) language
    for technical computing.
  • Matlab is case sensitive language

4
Facilitates
  • Math and computation
  • Data acquisition, data analysis and visualization
  • Modeling, simulation and prototyping
  • Scientific and engineering graphics
  • And many more

5
Matlab System
  • A Matlab system consist of Five main parts
  • Development Environment
  • Mathematical function library
  • Matlab Language
  • Graphics
  • Application Program Interface (API)

6
Starting Matlab
  • On windows platforms double-click on Matlab icon
  • On Unix/Linux platforms, type matlab at the
    operating system prompt
  • To quit type in windows . Select file followed by
    exit matlab. Or type quit in the operating system
    prompt.

7
Matlab (matrices and arrays)
  • A variable is a symbolic representation used to
    denote a quantity or expression
  • i.e a2
  • An array is a collection of variables
  • i.e b 2, 3, 4
  • A matrix is a rectangular array of numbers.
  • i.e c 1 2
  • 3 4
  • To make it simple. consider matlab store variable
    in form of matrices i.e a single variable as a
    matrix of 1 1
  • How will matlab store a set of five variables ?

8
Example
  • In the command window of matlab type
  • a1
  • And type
  • b2
  • Finally type
  • cab
  • The display value would be
  • c3
  • Note similarly we can assign different value to
    the variables by using built in math function
    provided by Matlab. i.e d cos(a)

9
Entering Matrices
  • To enter matrices
  • Separate the elements of a row with blanks or
    commas.
  • Use a semicolon, , to indicate the end of each
    row
  • Surround the entire list of elements with square
    brackets, .
  • i.e
  • A 16 3 2 13 5 10 11 8 9 6 7 12 4 15 14 1

10
Cont
  • A
  • 16 3 2 13
  • 5 10 11 8
  • 9 6 7 12
  • 4 15 14 1
  • known as Durer matrix
  • Once a matrices is entered its remember in the
    Matlab workspace and can be referred simply by
    its assigned name.

11
Operation on matrices
  • sum(x), transpose and diag operation
  • Matlab compute along the columns of a matrix
  • i.e sum(A)
  • gives a row vector containing the sum of the
    matrix columns
  • How about rows sum?
  • Easiest way is to take a transpose of matrix
    .Transpose Operation is denoted by apostrophe or
    single quote, . i.e A give the transpose (What
    is transpose of a matrix)
  • Can you Explain this operation sum(A)
  • This operation produce the sum of rows and
    transpose the result in the column format.

12
Cont
  • diag(A)
  • This operation show the element on the main
    diagonal of the matric
  • Explain this operation sum(diag(A))
  • This produces the sum of matrix element on it
    main diagonal
  • How about antidiagonal ?
  • fliplr(A) , flips the matrix from left to right
    then

13
Cont
  • Generating Matrices
  • Four built in function for matrices
  • zeros() all zeros i.e zzeros(2,4) create 2 4
    matrix whose elements are all zeros
  • ones() all ones i.e oones(2,4) create 24
    matrix whose elemenst are all ones
  • rand() Uniformally distributed random elements
  • Randn() Normally distributed random elements

14
Subscripts
  • The elements in row I and j of A is denoted by A
    (i,j).
  • i.e A(4 , 2 ) stands for fourth row and second
    column element which is 15
  • To compute the sum of element in the fourth
    column
  • A(1,4) A(2,4) A(3,4) A(4,4)
  • The matrix can be considered as one long vector
    array where
  • A (n) will represent the n element in position
    of that vector i.e A(8)15 which is also given by
    A(4,2)
  • What if we try A(4,5)?
  • It is an error as it exceed the matrix dimension
    but on the other hand, If you store a value i.e
    A(4,5 ) 23 the original matrix dimension size is
    increases to accommodate the new entry

15
Colon Operator
  • Is one of the most important operator
  • As spacing operator
  • i.e 15 mean increment by 1 upto 5
  • 100 -7 50 mean starting at 100 and decrement
    by 7 upto 50
  • Subscript expression
  • A (1k,j) mean first k elements of the jth column
    of A i.e A (14,4)
  • A(,end) where mean all the element and end
    refer to the last row or column
  • Explain this operation sum(116)/4?

16
Concatenation
  • Concatenation is the process of joining small
    matrices to make bigger ones.
  • The pair of square brackets, , is the
    concatenation operator
  • i.e B A A8 A16 A32
  • Results in an 8 8 matrices that is compose of
    sub matrix of A, A8, A16, A32

17
Rows, columns deletion
  • You can delete rows and columns from matrix using
    just pair of square brackets
  • i.e X A assigning a new matrix
  • X(,2) this delete the second column
  • How would you delete a single element?
  • X(n) where n is the element in the vector
    format of the matrix

18
Some Linear Algebra
  • Matrix matrix multiplication (inner product) is
    achieved by A B
  • Matrix .dot product multiplication is achieved by
    A. B
  • Inv(A) command gives the inverse of matrix
  • Symmetric matrix is when a matrix is added to
    its transpose i.e A A. Also A A produces
    a symmetric matrix
  • Try them now

19
Cont
  • Determinant 0 mean matrix is singular
  • i.e d det(A) .. So is it singular try
    ddet(Aa)
  • rref(A) gives the Reduced row echelon form
  • eig(A) give the eigenvalues

20
Some simple commands
  • a semicolon avoid command output to be
    displayed i.e t 15 Doesnt display the output
    of the t vector on the command line
  • clc command clear the output on the command line
  • Whos command shows the variable already created
    and their sizes

21
Help topics
  • In order to avail the built in help in matlab.
    Type
  • gtgt help
  • matlab\general -General purpose commands
  • matlab\ops Operators and special characters
  • matlab\lang -Programming language constructs
  • matlab\elmat -Elementary matrices and matrix
    manipulation
  • matlab\elfun -Elementary math functions
  • matlab\specfun -Specialized math functions
  • matlab\matfun -Matrix functions -numerical linear
    algebra
  • matlab\datafun -Data analysis and Fourier
    transforms
  • matlab\polyfun -Interpolation and polynomials
  • matlab\funfun -Function functions and ODE solvers
  • matlab\sparfun -Sparse matrices
  • matlab\scribe -Annotation and Plot Editing
  • matlab\graph2d -Two dimensional graphs
  • matlab\graph3d -Three dimensional graphs
  • matlab\graphics -Handle Graphics.
  • etc...

22
M-files
  • M-files are text files containing matlab code.
  • Files extension is .m
  • For example create a matrix in a file i.e b 1
    2 3 4 and save this file as bmatrix.m
  • You can simply call this matrix by typing the
    name of the file in the command window of Matlab.
    This will add the matrix b to the variable
    dictionary of matlab that matrix b is now also be
    accessible as simple typing b.

23
M-files
  • To use personalized folder . You need to change
    the working directory by typing cd \directory
    where directory is the path to the folder where
    you just save an m file
  • i.e function zaplusb(a,b)
  • Zab
  • Save the file as z and run it

24
Financial toolbox
  • Mean-variance and CVaR-based object oriented
    portfolio optimization
  • Cash flow analysis, risk analysis, financial
    time-series modeling, date math and calendar math
  • Regression and estimation with missing data
  • Basic Black-Scholes, Black and binomial option
    pricing
  • Financial times serial analysis
  • Technical indicators and financial charts
  • And more

25
Key features

26
  • Thank you
  • Q A
Write a Comment
User Comments (0)
About PowerShow.com