Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan Math Review with Matlab: Fundamentals Symbolic Math Toolbox."— Presentation transcript:

1

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

3 Symbolic Toolbox:Fundamentals 2 Fundamentals of Matlab’s Symbolic Toolbox n Creating Symbolic Variables Creating Symbolic Variables n Defining Symbolic Expressions Defining Symbolic Expressions n Defining Numerical Representation Defining Numerical Representation n Converting Symbolic Variables to Doubles Converting Symbolic Variables to Doubles n Creating Real Symbolic Variables Creating Real Symbolic Variables n Creating Complex Symbolic Variables Creating Complex Symbolic Variables n Manipulating Abstract Functions Manipulating Abstract Functions

4 Symbolic Toolbox:Fundamentals 3 Defining Symbolic Variables Use sym to create a symbolic variable x: » x=sym('x'); Use syms to create several symbolic variables at one time Use who to view al variables in the workspace » who Your variables are: a b x y » syms y a b

5 Symbolic Toolbox:Fundamentals 4 Use whos to view all workspace variables with their associated size, bytes, and class information Viewing Workspace Variables » 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

6 Symbolic Toolbox:Fundamentals 5 Symbolic Expressions n Symbolic Expressions: Symbolic and Numerical Conversions to perform a mathematical operation and create a new symbolic variable delta: » f = 2*x^2 + x + 1; » g = a*x^2 + b*x + 5 g = a*x^2+b*x+5 » delta = sym('1+sqrt(2)/2'); » f = delta^2 + delta; f = (1+1/2*2^(1/2))^2+1+1/2*2^(1/2)

7 Symbolic Toolbox:Fundamentals 6 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 Numerical Representation '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)

8 Symbolic Toolbox:Fundamentals 7 » rho=(1+sqrt(5)/2) » rho_float = sym(rho,'f') rho_float = '1.0f1bbcdcbfa54'*2^(1) » rho_decimal = sym(rho,'d') rho_decimal = 2.1180339887498949025257388711907 Symbolic Representation Example Symbolic Variables rho = 2.1180 Double-Precision Floating Point Variable

9 Symbolic Toolbox:Fundamentals 8 digits, by itself, displays the current accuracy (default = 32 digits) 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

10 Symbolic Toolbox:Fundamentals 9 Digits Example » digits Digits = 32 » rho=(1+sqrt(5)/2); » rho_decimal = sym(rho,'d') Default Precision (32 Digits) Adjusted Precision (7 Digits) » digits(7) » rho_decimal_7=sym(rho,'d') rho_decimal_7 = 2.118034 rho_decimal = 2.1180339887498949025257388711907

11 Symbolic Toolbox:Fundamentals 10 » x=sym(3);y=sym(4); » z_sym = x/y z_sym = 3/4 » z_float = double(z_sym) z_float = 0.7500 Double Command The double command coverts a symbolic variable to a general Matlab double floating point number Symbolic Variable Double Float Variable

12 Symbolic Toolbox:Fundamentals 11 Declaring Real Variables n To declare real symbolic variables: n Or use shorthand notation: » x = sym('x','real'); » y = sym('y','real'); » syms x y real » who Your variables are: x y

13 Symbolic Toolbox:Fundamentals 12 Declaring Complex Variables To construct a complex number use i or j to represent the imaginary part Use real to find the real part » syms x y » z=x+i*y; % or z=x+j*y z= x+i*y Use imag to find the imaginary part » z_real = real(z) z_real = x » z_imag = imag(z) z_imag = y

14 Symbolic Toolbox:Fundamentals 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 x is 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)

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

16 Symbolic Toolbox:Fundamentals 15 Abstract Function Example n Find the determinant and inverse of the matrix z: » syms a b c » z=[ a 0 0; 0 b 0; 0 0 c] z = [ a, 0, 0] [ 0, b, 0] [ 0, 0, c] » determinant = det(z) determinant = a*b*c » inverse = inv(z) inverse = [ 1/a, 0, 0] [ 0, 1/b, 0] [ 0, 0, 1/c]

17 Symbolic Toolbox:Fundamentals 16 Matrix Manipulation Example n 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]

18 Symbolic Toolbox:Fundamentals 17 Summary n Matlab can be used to create and manipulate symbolic variables and expressions n Symbolic variables representing numbers can be displayed with adjustable accuracy n Symbolic variables can be declared as real, complex, or converted to the default unreal state n Abstract functions can be created and manipulated symbolically The double command converts symbolic variables into Matlab double precision floating point variables


Download ppt "S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan Math Review with Matlab: Fundamentals Symbolic Math Toolbox."

Similar presentations


Ads by Google