1 / 17

Symbolic Math Toolbox

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 Symbolic Toolbox. Creating Symbolic Variables Defining Symbolic Expressions Defining Numerical Representation

skyler
Download Presentation

Symbolic Math Toolbox

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. Fundamentals of Matlab’s 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 » x=sym('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 » n=1.0;t=[1.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 = 2*x^2 + x + 1; » g = a*x^2 + b*x + 5 g = a*x^2+b*x+5 • Symbolic and Numerical Conversions to perform a mathematical operation and create a new symbolic variable delta: » delta = sym('1+sqrt(2)/2'); » f = delta^2 + delta; f = (1+1/2*2^(1/2))^2+1+1/2*2^(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 Variables Symbolic Representation Example » rho=(1+sqrt(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=(1+sqrt(5)/2); » rho_decimal = sym(rho,'d') Default Precision (32 Digits) rho_decimal = 2.1180339887498949025257388711907 » digits(7) » rho_decimal_7=sym(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 » x=sym(3);y=sym(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 • To construct a complex number use i or j to represent the imaginary part » syms x y » z=x+i*y; % or z=x+j*y z= x+i*y » 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 » x=sym('x','real'); » conj(x) ans = x • If xis real, the complex conjugate of x will be x • If x is unreal, the complex conjugate of can not be further simplified » x=sym('x','unreal'); » conj(x) ans = conj(x)

  14. Abstract Functions • A symbolic variable can represent an abstract function: f=sym('f(x)')where the input argument is a string • Abstract functions are useful for solving algebraic and differential equations » f=sym('2*x+2') f = 2*x+2

  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 = a*b*c » 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

More Related