Introduction to MATLAB - PowerPoint PPT Presentation

About This Presentation
Title:

Introduction to MATLAB

Description:

Introduction to MATLAB – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 14
Provided by: david400
Learn more at: https://jan.ucc.nau.edu
Category:

less

Transcript and Presenter's Notes

Title: Introduction to MATLAB


1
Introduction to MATLAB
  • MATLAB is a mathematics program that works by
    either typing in commands or by writing programs
  • Typing x5sqrt(83)/(53exp(.2)) will result in
    x .3609
  • MATLAB handles matrix mathematics and complex
    number arithmetic with ease

2
Matlabs Workspace
  • Each command or each program creates a set of
    variables with values in the workspace
  • Values are kept until you no longer need them
  • Use clear to wipe the workspace clean
  • Use clear x to eliminate the variable x
  • Use clear variables to clear all variables
  • Clear the screen of text by using clc on the
    command line or choosing Clear Session under Edit
    in the menu. This does not clear the variables.

3
Matlabs Workspace
  • You can check your variables at any time
  • who generates a listing of all variables
  • whos generates a listing of all variables plus
    the size, bytes and class of the variables
  • Choosing Show Workspace under the File menu
    brings up a window showing the same information
    as whos)
  • Type help who for more detailed information
  • Type the variable to see its value(s)

4
Matlab Built-In Functions
  • Matlab commands and functions are broken down
    into many categories
  • Type help elfun
  • trigonometric functions
  • exponential functions
  • complex number functions
  • rounding/remainder functions

5
Common Math Functions
  • Trigonometric cos, sin, tan, atan
  • Be sure to use radians in the argument
  • Square root sqrt(2) yields 1.414
  • Natural Log log(3) yields 1.0986
  • Base 10 Log log10(4) yields .6021
  • Base 2 Log log2(4) yields 2
  • Exponential exp(2) yields e2 7.3891

6
Complex Number Functions
  • Enter in rectangular form
  • x43j or x43i or xcomplex(4,3)
  • Magnitude abs(x) yields 5
  • Phase angle angle(x) yields .6435 radians
  • Complex conjugate conj(x) yields 4-3j
  • Real part real(x) yields 4
  • Imaginary part imag(x) yields 3

7
Matlab Matrix Math
  • Matrices are rectangular arrays of numbers
  • Matlab uses matrix math to simplify many
    calculations
  • Each element in a matrix can be accessed using
    its row and column m(row,column)
  • An entire row or column can be accessed to form a
    vector m( ,column) or m(row, )

8
Generating a Vector
  • Generate a vector by listing its values
  • Rowvector1 2 3 4 5 6 7 8 9
  • Columnvector123456789 the semicolon
    starts a new row
  • Create a row vector with a constant interval
  • Tstart value increment end value
  • T0 2 10 gives T0 2 4 6 8 10
  • Tlinspace(start value, end value, number wanted)
  • Tlinspace(0,10,5) gives T0 2.5 5 7.5 10

9
Generating a Vector
  • You can create a row vector with logarithmic
    spacing
  • Tlogspace(starting power of 10, ending power of
    10, number of values wanted)
  • Tlogspace(0,2,4) gives
  • T1 4.6416 21.5443 100

10
Generating a Matrix
  • You can create a matrix by entering each row with
    semicolons between each row
  • A 3 4 7 5 7 3 2 0 6
  • 3 4 -7
  • A 5 7 3
  • 2 0 6

11
Matrices and Sets of Equations
  • Matrices can be used to represent a system of
    equations and solve it
  • 3x4y-7z10
  • 5x-7y3z-6
  • 2x-6z6
  • The matrix equation implements the above system
  • 3 4 -7 x 10
  • 5 7 3 . y -6 or A S C
  • 2 0 6 z 6

12
Matlab Solution of ASC
  • A3 4 7 5 7 3 2 0 6
  • C10 -6 6
  • Premultiply both sides by the inverse of A
  • inv(A) A S inv(A) C
  • Which simplifies to S inv(A) C
  • 0.3140 or x
    .3140
  • Results in S 0.6977 or y .6977
  • -0.8953 or z
    -.8953

13
Running Matlab Programs
  • Under file, select open
  • Find the M-file that you want to run
  • The M-file should appear in the editor window
  • Modify the M-file as needed
  • Under debug, choose run
  • Results should be displayed in the main window
  • Plots should be displayed in new figure windows
Write a Comment
User Comments (0)
About PowerShow.com