S. Awad, Ph.D. - PowerPoint PPT Presentation

About This Presentation
Title:

S. Awad, Ph.D.

Description:

Math Review with Matlab: Symbolic Math Toolbox Fundamentals S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan Fundamentals of Matlab s ... – PowerPoint PPT presentation

Number of Views:67
Avg rating:3.0/5.0
Slides: 18
Provided by: EC9
Category:

less

Transcript and Presenter's Notes

Title: S. Awad, Ph.D.


1
Symbolic Math Toolbox
Math Review with Matlab
Fundamentals
  • S. Awad, Ph.D.
  • M. Corless, M.S.E.E.
  • E.C.E. Department
  • University of Michigan

2
Fundamentals of Matlabs Symbolic Toolbox
  • Creating Symbolic Variables
  • Defining Symbolic Expressions
  • Defining Numerical Representation
  • Converting Symbolic Variables to Doubles
  • Creating Real Symbolic Variables
  • Creating Complex Symbolic Variables
  • Manipulating Abstract Functions

3
Defining Symbolic Variables
xsym('x')
  • Use sym to create a symbolic variable x

syms y a b
  • Use syms to create several symbolic variables at
    one time

who Your variables are a b x y
  • Use who to view al variables in the workspace

4
Viewing Workspace Variables
  • Use whos to view all workspace variables with
    their associated size, bytes, and class
    information

n1.0t1.1 2.2 3.3 whos Name Size
Bytes Class a 1x1
126 sym object b 1x1 126
sym object n 1x1 8 double
array t 1x3 24 double
array x 1x1 126 sym object
y 1x1 126 sym object Grand
total is 12 elements using 536 bytes
5
Symbolic Expressions
  • Symbolic Expressions

f 2x2 x 1 g ax2 bx 5 g
ax2bx5
  • Symbolic and Numerical Conversions to perform a
    mathematical operation and create a new symbolic
    variable delta

delta sym('1sqrt(2)/2') f delta2
delta f (11/22(1/2))211/22(1/2)
6
Numerical Representation
  • The command sym(A,flag) converts a numeric scalar
    or matrix, A, to symbolic form
  • The flag argument specifies the technique for
    converting floating point numbers

'f' Exactly represents Floating Point values in
the form '1.F'2(e) or '-1.F'2(e) where F is a
string of 13 hexadecimal digits and e is an
integer. (This form may not be convenient for
subsequent manipulation)
'd' Represents Decimal numbers where the number
of digits is taken from the current setting of
DIGITS (described later)
7
Symbolic Representation Example
rho(1sqrt(5)/2)
  • Double-Precision
  • Floating Point
  • Variable

rho 2.1180
rho_float sym(rho,'f') rho_float
'1.0f1bbcdcbfa54'2(1)
rho_decimal sym(rho,'d') rho_decimal
2.1180339887498949025257388711907
8
Digits Command
  • The digits command is used to set the number of
    digits of accuracy used for future numeric
    computations on symbolic variables
  • digits(n) sets accuracy to n digits for
    subsequent calculations. Where n represents an
    integer
  • digits, by itself, displays the current accuracy
    (default 32 digits)

9
Digits Example
digits Digits 32 rho(1sqrt(5)/2)
rho_decimal sym(rho,'d')
  • Default Precision (32 Digits)

rho_decimal 2.1180339887498949025257388711907
digits(7) rho_decimal_7sym(rho,'d')
rho_decimal_7 2.118034
Adjusted Precision (7 Digits)
10
Double Command
  • The double command coverts a symbolic variable to
    a general Matlab double floating point number

xsym(3)ysym(4) z_sym x/y z_sym 3/4

Symbolic Variable
z_float double(z_sym) z_float 0.7500
Double Float Variable
11
Declaring Real Variables
  • To declare real symbolic variables

x sym('x','real') y sym('y','real')
  • Or use shorthand notation

syms x y real who Your variables are x
y
12
Declaring Complex Variables
syms x y zxiy or zxjy z xiy
  • To construct a complex number use i or j to
    represent the imaginary part

z_real real(z) z_real x
  • Use real to find the real part
  • Use imag to find the imaginary part

z_imag imag(z) z_imag y
13
Unreal
  • The 'unreal' argument to sym can be used to
    convert a real variable to a purely formal
    variable with no additional properties

xsym('x','real') conj(x) ans x
  • If x is real, the complex conjugate of x will be x
  • If x is unreal, the complex conjugate of can not
    be further simplified

xsym('x','unreal') conj(x) ans conj(x)
14
Abstract Functions
  • A symbolic variable can represent an abstract
    function fsym('f(x)')where the input argument
    is a string
  • Abstract functions are useful for solving
    algebraic and differential equations

fsym('2x2') f 2x2
15
Abstract Function Example
syms a b c z a 0 0 0 b 0 0 0 c z a,
0, 0 0, b, 0 0, 0, c
  • Find the determinant and inverse of the matrix z

determinant det(z) determinant abc
inverse inv(z) inverse 1/a, 0, 0
0, 1/b, 0 0, 0, 1/c
16
Matrix Manipulation Example
  • Change the first element of the matrix from a to
    g

z(1,1)'g' z g, 0, 0 0, b, 0 0,
0, c
17
Summary
  • Matlab can be used to create and manipulate
    symbolic variables and expressions
  • Symbolic variables representing numbers can be
    displayed with adjustable accuracy
  • The double command converts symbolic variables
    into Matlab double precision floating point
    variables
  • Symbolic variables can be declared as real,
    complex, or converted to the default unreal state
  • Abstract functions can be created and manipulated
    symbolically
Write a Comment
User Comments (0)
About PowerShow.com