MATLAB Lecture 5 School of Mathematical Sciences Xiamen University http∥gdjpkc.xmu.edu.cr MATLAB Lecture 5-Symbol computation 符号计算 Ref: Symbolic Math Toolbox-Getting Started Symbolic Math Toolbox-Using the Symbolic Math Toolbox These versions of the Symbolic Math Toolboxes are designed to work with MATLAB 6 or greater and Maple 8 data type数据类型 toolbox工具箱 symbol computation符号计算 symbolic object符号对象 numerical value数值 variable变量 represent表示 store存储 string(字符)串 expression表达式 equation方程 substitute代换,代入,替换 function函数 abstract抽象的 indeterminate不确定的 circulant matrⅸx循环矩阵 nested/ horner嵌套的 collecting合并(的) expand展开 factor因子 factoring因式分解 algebraic代数的 trigonometrIc三角(学)的,三角(法)的 恒等式 transform转换 simplification化简 ● Some funetions sym syms simple simplify collect expand horner factor *findsym double *eval Symbolic math Toolbox Y Symbolic Objects The symbolic Math Toolbox defines a new matlab data type called a symbolic object (See Programming and Data Types in the online MATLAB documentation for an introduction to MATLAB classes and objects. )Internally, a symbolic object is a data structure that stores a string representation of the symbol. The Symbolic Math Toolbox uses symbolic objects to represent symbolic variables, expressions, and matrices. The actual computations involving symbolic objects are performed primarily by maple, mathematical software developed by Waterloo Maple, Inc The following example illustrates the difference between a standard matlAB data type uch as double, and the corresponding symbolic object. The matlab command > sqrt(2) %returns a floating-point decimal number
MATLAB Lecture 5 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Lec51 MATLAB Lecture 5 – Symbol Computation 符号计算 Ref: Symbolic Math Toolbox→Getting Started Symbolic Math Toolbox→Using the Symbolic Math Toolbox These versions of the Symbolic Math Toolboxes are designed to work with MATLAB 6 or greater and Maple 8. l Vocabulary: data type 数据类型 toolbox 工具箱 symbol 符号 symbol computation 符号计算 symbolic object 符号对象 numerical value 数值 variable 变量 represent 表示 store 存储 string (字符)串 expression 表达式 equation 方程 substitute 代换,代入,替换 function 函数 abstract 抽象的 indeterminate 不确定的 circulant matrix 循环矩阵 nested/horner 嵌套的 collecting 合并(的) expand 展开 factor 因子 factoring 因式分解 algebraic 代数的 trigonometric 三角(学)的,三角(法)的 identities 恒等式 transform 转换 simplification 化简 l Some functions sym syms simple simplify collect expand horner factor *findsym *sum *double *eval l Symbolic Math Toolbox ² Symbolic Objects The Symbolic Math Toolbox defines a new MATLAB data type called a symbolic object. (See Programming and Data Types in the online MATLAB documentation for an introduction to MATLAB classes and objects.) Internally, a symbolic object is a data structure that stores a string representation of the symbol. The Symbolic Math Toolbox uses symbolic objects to represent symbolic variables, expressions, and matrices. The actual computations involving symbolic objects are performed primarily by Maple, mathematical software developed by Waterloo Maple, Inc. The following example illustrates the difference between a standard MATLAB data type, such as double, and the corresponding symbolic object. The MATLAB command >> sqrt(2) %returns a floatingpoint decimal number: ans =
ATLAB Lecture 5 School of Mathematical Sciences Xiamen University http∥gdjpkc.xmu.edu.cr 14142 >>a=sqrt(sym(2)) %using symbolic notation for the square root operation MATLAB gives the result 2(112), which means √2, without actually calculating a numerical value. MATLAB records this symbolic expression in the string that represents 2(1/2). You can always obtain the numerical value of a symbolic object with the double > double(a) ans 14142 Notice that the result is indented, which tells you it has data type double. Symbolic results are not indented When you create a fraction involving symbolic objects, MATLAB records the numerator and > sym(2)/sym(5)+sym( 1)/sym(3) %performs arithmetic on symbolic objects ll/15 >>2/5+1/3 %gives the answer as a decimal fraction 0.7333 The Symbolic Math Toolbox enables you to perform a variety of symbolic calculations that arise in mathematics and science Y Creating Symbolic Variables and Expressions >>x=sym('x): %construct symbolic variable >>a=sym(alpha+2): %construct symbolic expression >>rho= sym((1 sqrt(5))/2); %use a symbolic variable to represent the golden ratio >>fl= rho- rho-1 f (1/2+12*5^(1/2)2-3/2-12*5^(1/2) >>eval(fl) %evaluate fl >>f2=sym(a*x2+bx+c) assigns the symbolic expression to the variable f2 To perform symbolic math operations(e.g, Integration, differentiation, substitution, etc. )on t2, you need to create the variables explicitly. A better alternative is to enter the command >>a=sym('a), b= sym():c=sym('c):x=sym('x)
MATLAB Lecture 5 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Lec52 1.4142 >> a = sqrt(sym(2)) %using symbolic notation for the square root operation a = 2^(1/2) MATLAB gives the result 2^(1/2), which means 2 , without actually calculating a numerical value. MATLAB records this symbolic expression in the string that represents 2^(1/2). You can always obtain the numerical value of a symbolic object with the double command: >> double(a) ans = 1.4142 Notice that the result is indented, which tells you it has data type double. Symbolic results are not indented. When you create a fraction involving symbolic objects, MATLAB records the numerator and denominator. For example: >> sym(2)/sym(5)+sym(1)/sym(3) %performs arithmetic on symbolic objects ans = 11/15 >> 2/5 + 1/3 %gives the answer as a decimal fraction ans = 0.7333 The Symbolic Math Toolbox enables you to perform a variety of symbolic calculations that arise in mathematics and science. ² Creating Symbolic Variables and Expressions >> x = sym('x'); %construct symbolic variable >> a = sym('alpha+2'); %construct symbolic expression >> rho = sym('(1 + sqrt(5))/2'); %use a symbolic variable to represent the golden ratio >> f1 = rho^2 rho 1 f1 = (1/2+1/2*5^(1/2))^23/21/2*5^(1/2) >> eval(f1) %evaluate f1 ans = 0 >> f2 = sym('a*x^2 + b*x + c') % assigns the symbolic expression to the variable f2 To perform symbolic math operations (e.g., integration, differentiation, substitution, etc.) on f2, you need to create the variables explicitly. A better alternative is to enter the commands >> a = sym('a'); b = sym('b'); c = sym('c'); x = sym('x') or simply
ATLAB Lecture 5 School of Mathematical Sciences Xiamen University http∥gdjpkc.xmu.edu.cr >>f2=sym(a*x 2+b*x+c) >>12=a*x^2+b*x+c In general, you can use sym or syms to create symbolic variables. We recommend you use syms because it requires less typing If you want to generation an symbolic equation, the code f2=a*x 2+b x+c=0 is illegal The correct command is f2=sym(a*x 2+bx+c=0)or f2=sym(a*x 2+b*x+c=0") Note To create a symbolic expression that is a constant, you must use the sym command >>s 5=sym(5); s 5/3 create a symbolic 5 5/3 create a number 5 1.6667 If you set a variable equal to a symbolic expression, and then apply the syms command to the variable, MATLAB removes the previously defined expression from the variable >> syms a >>f3=a+b %create a symbolic variable f, whose value is a symbolic expression a+b 13 > syms f3 removes the previously defined expression from the variable >>f ☆ The subs command You can substitute a numerical value for a symbolic variable using the subs command to >>f4=2*x2-3x+I': %create a'charvariable f4, equivalent to sym f4 f4=2*x^2-3*x+1 >> subs(f4, 1) %substitute the val 0 *Note To substitute a matrix A into the symbolic expression f, use the command polyvalm( sym2poly(f), A), which replaces all occurrences of x by A, and replaces the constant term of f with the constant times an identity matrix A=[1234 3 polyram( Lec5-3
MATLAB Lecture 5 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Lec53 >> syms a b c x >> f2= sym('a*x^2 + b*x + c') or >> f2= a*x^2 + b*x + c In general, you can use sym or syms to create symbolic variables. We recommend you use syms because it requires less typing. If you want to generation an symbolic equation, the code f2= a*x^2 + b*x + c=0 is illegal. The correct command is f2= sym('a*x^2 + b*x + c=0') or f2= sym('a*x^2 + b*x + c=0'). Note To create a symbolic expression that is a constant, you must use the sym command. >> s_5 = sym('5'); s_5/3 % create a symbolic 5 ans = 5/3 >> a_5 = 5; a_5/3 % create a number 5 ans = 1.6667 If you set a variable equal to a symbolic expression, and then apply the syms command to the variable, MATLAB removes the previously defined expression from the variable. >> syms a b; >> f3 = a + b %create a symbolic variable f3, whose value is a symbolic expression a+b f3 = a+b >> syms f3 % removes the previously defined expression from the variable. >> f3 f3= f3 ² The subs Command You can substitute a numerical value for a symbolic variable using the subs command. to >> f4 =’2*x^2 3*x + 1’ ; %create a ‘char’ variable f4, equivalent to sym f4; … f4=’2*x^2 3*x + 1’; >> subs(f4,1) %substitute the value x = 1 in f4, i.e. 2*1^23*1+1 ans = 0 *Note To substitute a matrix A into the symbolic expression f, use the command polyvalm(sym2poly(f), A), which replaces all occurrences of x by A, and replaces the constant term of f with the constant times an identity matrix. >> A=[1 2;3 4] A = 1 2 3 4 >> polyvalm(sym2poly(f4), A)
ATLAB Lecture 5 School of Mathematical Sciences Xiamen University http∥gdjpkc.xmu.edu.cr ?? Function'sym2poly' is not defined for values of class'char' > syms f4; %define f4 as an symbolic variable >>f4 =sym(2**x+1) assigns the symbolic expression to the variable f4 >> syms x;科4=2*x^2-3*x+1 2*x^23*x+1 > polyvalm(sym2poly(f4),A) compute matrix polynomial 2*A2-3*A+I 21 33 When your expression contains more than one variable, you can specify the variable for which you want to make the substitution >> syms x y >>f5=x2 y+5*sqrt(y) >>subs(f5, x, 3) %substitute the value x=3 in the symbolic expression 9*y+15y^(1/2) > subs(fs, y, 3) %to substitute y=3 ans 3*x^2+5*x*3^(1/2) t Creating a Symbolic Matrix A circulant matrix has the property that each row is obtained from the previous one by cyclically permuting the entries one step forward. You can, using the commands c:baca b %create the circulant matrix a whose elements are a, b, and c [b, c,a [c, a, b] Since a is circulant the sum over each row and column is the same. To check this for the first row and second column enter the command >>sum(A(1,) a+b+c > sum(A(l, ))==sum(A( 2)) This is a logical test to check whether the sum of .. the first row is equal to that of the second row It implies that the sum of the first row is equal to that of the second row. If the answer is 0, it means the sum of the first row is not equal to that of the second row syms alpha beta Lec5-4
MATLAB Lecture 5 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Lec54 ??? Function 'sym2poly' is not defined for values of class 'char'. >> syms f4; %define f4 as an symbolic variable >> f4 =sym('2*x^2 3*x + 1') % assigns the symbolic expression to the variable f4 or >> syms x; f4 = 2*x^2 3*x + 1 f4 = 2*x^2 3*x + 1 >> polyvalm(sym2poly(f4), A) % compute matrix polynomial 2*A^23*A+I ans = 12 14 21 33 When your expression contains more than one variable, you can specify the variable for which you want to make the substitution. >> syms x y >> f5 = x^2*y + 5*x*sqrt(y); >> subs(f5, x, 3) %substitute the value x = 3 in the symbolic expression ans = 9*y+15*y^(1/2) >> subs(f5, y, 3) %to substitute y = 3 ans = 3*x^2+5*x*3^(1/2) ² Creating a Symbolic Matrix A circulant matrix has the property that each row is obtained from the previous one by cyclically permuting the entries one step forward. You can, using the commands >> syms a b c >> A = [a b c; b c a; c a b] %create the circulant matrix A whose elements are a, b, and c A = [ a, b, c ] [ b, c, a ] [ c, a, b ] Since A is circulant, the sum over each row and column is the same. To check this for the first row and second column, enter the command >> sum(A(1,:)) ans = a+b+c >> sum(A(1,:)) == sum(A(:,2)) % This is a logical test to check whether the sum of … the first row is equal to that of the second row. ans = 1 It implies that the sum of the first row is equal to that of the second row. If the answer is 0, it means the sum of the first row is not equal to that of the second row. >> syms alpha beta;
ATLAB Lecture 5 School of Mathematical Sciences Xiamen University http∥gdjpkc.xmu.edu.cr > A(2, 3)=beta; % replace the(2, 3)entry of A with beta >>A=subs(A, b, alpha) %replace the variable b with alpha A I alpha, From this example, you can see that using symbolic objects is very similar to using regular MATLAB numeric objec 令 Simplifications pretty >>syms x f=x^3-6*x^2+11*x-6 >> >>h=-6+(11+(-6+x)*x)*x > pretty(f), pretty(g), pretty(h) %generate their pretty printed forms 32 6x+11x-6 (x-1)(x-2)(X-3) -6+(11+(-6+x)x)x collecto) views f as a polynomial in its symbolic variable, say x, and collects all the coefficients with the same power of x. A second argument can specify the variable in which to collect terms if there is more than one candidate collect(f) x-1)*(x-2)*(x-3) x×36*×2+116 x°(x°(X-6)+116 x^3-6*x^2+11*x-6 (1+x)°t+x*t 2*x*t+t expand(d distributes products over sums and applies other identities invol ving functions of sums (x-1)*(x-2)*(x-3) x^3-6*x^2+11*x-6 x(x*(x-6)+11)-6 x^3-6*x^2+11*x-6 exp(a+b) p(a)°exp(b) cos(x+y) sIn(xsIl n(y) cos(3*acos(x)) 4*x^3-3*x transforms a symbolic polynomial f into its horner
MATLAB Lecture 5 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Lec55 >> A(2,3) = beta; % replace the (2,3) entry of A with beta >> A = subs(A,b,alpha) %replace the variable b with alpha A = [ a, alpha, c] [ alpha, c, beta] [ c, a, alpha] From this example, you can see that using symbolic objects is very similar to using regular MATLAB numeric objects. ² Simplifications pretty >> clear >> syms x >> f = x^36*x^2+11*x6; >> g = (x1)*(x2)*(x3); >> h = 6+(11+(6+x)*x)*x; >> pretty(f), pretty(g), pretty(h) %generate their pretty printed forms 3 2 x 6 x + 11 x 6 (x 1) (x 2) (x 3) 6 + (11 + (6 + x) x) x collect collect(f) views f as a polynomial in its symbolic variable, say x, and collects all the coefficients with the same power of x. A second argument can specify the variable in which to collect terms if there is more than one candidate. f collect(f) (x1)*(x2)*(x3) x^36*x^2+11*x6 x*(x*(x6)+11)6 x^36*x^2+11*x6 (1+x)*t + x*t 2*x*t+t expand expand(f) distributes products over sums and applies other identities involving functions of sums. f expand(f) a*(x + y) a*x + a*y (x1)*(x2)*(x3) x^36*x^2+11*x6 x*(x*(x6)+11)6 x^36*x^2+11*x6 exp(a+b) exp(a)*exp(b) cos(x+y) cos(x)*cos(y)sin(x)*sin(y) cos(3*acos(x)) 4*x^33*x horner horner(f) transforms a symbolic polynomial f into its Horner, or nested, representation
ATLAB Lecture 5 SchoolofMathematicalSciencesXiamenUniversityhttp://gdjpkc.xmu.edu.cr horner(f) x^3-6*x^2+11*x-6 -6+(116)*x)*x 1+2.2*x+3.3*x^2 10(15+330)* factor If f is a polynomial with rational coefficients, the statement factor( expresses f as a product of polynomials of lower degree with rational coefficients If f cannot be factored over the rational numbers the result is f itself x^3-6*x^2+11*x-6 (X-1)°(X-2)*(x-3) x^3-6*x^2+11*x-5 x^3-6*x^2+11*x-5 x^6+1 2+1)(x24x2+1) Here is another example involving factor. It factors polynomials of the form xn+ 1. This code >>f= factor(p); >>[p,f returns a matrix with the polynomials in its first column and their factored forms in its x^2+1 x^3+1 (x+1)°(x~2-x+1) x^4+1, x^5+1 (x+1)*(x~4-x^~3+x^2-x+1) (x^2+1)*(x^4-x^2+1)] x^7+1,(x+1)*(1-x+x^2-x^3+x4-x^5+x^6)] 8+ x^8+1] (x+1)*(x^2-x+1)°(x^6-x^3+1) simplify The simplify function is a powerful, general purpose tool that applies a number of algebraic dentities involving sums, integral powers, square roots and other fractional powers, as well as a number of functional identities involving trig functions, exponential and log functions, Bessel functions, hypergeometric functions, and the gamma function. simplify(f) x(x*(x-6)+11)-6 x^3-6*x^2+11*x-6 (1-x^2)(1-x) x+1 (1/a^3+6a^2+12/a+8y(1/3) (2*a+1)y3/a3)^(1/3) syms x y positive: log(x y) log(x)+log(y) exp(x)*exp(y p(xty) cos(x)2+ sin(x)2 Lec5-6
MATLAB Lecture 5 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Lec56 f horner(f) x^36*x^2+11*x6 6+(11+(6+x)*x)*x 1.1+2.2*x+3.3*x^2 11/10+(11/5+33/10*x)*x factor If f is a polynomial with rational coefficients, the statement factor(f) expresses f as a product of polynomials of lower degree with rational coefficients. If f cannot be factored over the rational numbers, the result is f itself. f factor(f) x^36*x^2+11*x6 (x1)*(x2)*(x3) x^36*x^2+11*x5 x^36*x^2+11*x5 x^6+1 (x^2+1)*(x^4x^2+1) Here is another example involving factor. It factors polynomials of the form x^n + 1. This code >> syms x; >> n = (1:9)'; >> p = x.^n + 1; >> f = factor(p); >> [p, f] returns a matrix with the polynomials in its first column and their factored forms in its second. [ x+1, x+1 ] [ x^2+1, x^2+1 ] [ x^3+1, (x+1)*(x^2x+1) ] [ x^4+1, x^4+1 ] [ x^5+1, (x+1)*(x^4x^3+x^2x+1) ] [ x^6+1, (x^2+1)*(x^4x^2+1) ] [ x^7+1, (x+1)*(1x+x^2x^3+x^4x^5+x^6) ] [ x^8+1, x^8+1 ] [ x^9+1, (x+1)*(x^2x+1)*(x^6x^3+1) ] simplify The simplify function is a powerful, general purpose tool that applies a number of algebraic identities involving sums, integral powers, square roots and other fractional powers, as well as a number of functional identities involving trig functions, exponential and log functions, Bessel functions, hypergeometric functions, and the gamma function. f simplify(f) x*(x*(x6)+11)6 x^36*x^2+11*x6 (1x^2)/(1x) x+1 (1/a^3+6/a^2+12/a+8)^(1/3) ((2*a+1)^3/a^3)^(1/3) syms x y positive; log(x*y) log(x)+log(y) exp(x) * exp(y) exp(x+y) cos(x)^2 + sin(x)^2 1
ATLAB Lecture 5 School of Mathematical Sciences Xiamen University http∥gdjpkc.xmu.edu.cr SI The simple function has the unorthodox mathematical goal of finding a simplification of an expression that has the fewest number of characters. Of course, there is little mathematical ustification for claiming that one expression is"simpler"than another just because its ASCll representation is shorter, but this often proves satisfactory in practice The simple function achieves its goal by independently applying simplify, collect, factor, and other simplification functions to an expression and keeping track of the lengths of the results The simple function then returns the shortest result simpled displays each trial simplification and the simplification function that produced it in the MATLAB command window. The simple function then returns the shortest result > simple(cos(x)2+ sin(x)2) %displays the following alternative simplifications in the matlab command window simplify cos(x )2+sin(x )2 cos(x)2+sin(x)2 cos(x2+sin(x) (1/2*exp(i*x)+1/2/exp(1*x)^2-1/4*(exp(i*x)-1/exp(i*x)^2 convert(sincos) cos(x2+sin(x)2 convert( tan) (1tan(1/2*x)^2)2/(1+tan(1/2*x)^2)2+ 4°tan(1/2*x)y2/(1+tan(1/2*x)^2)2 collect() cos(x)2+sin(x)2 f= simple) simply returns the shortest expression found f= simple(cos(x)2+sin(x)2)
MATLAB Lecture 5 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Lec57 simple The simple function has the unorthodox mathematical goal of finding a simplification of an expression that has the fewest number of characters. Of course, there is little mathematical justification for claiming that one expression is "simpler" than another just because its ASCII representation is shorter, but this often proves satisfactory in practice. The simple function achieves its goal by independently applying simplify, collect, factor, and other simplification functions to an expression and keeping track of the lengths of the results. The simple function then returns the shortest result. simple(f) displays each trial simplification and the simplification function that produced it in the MATLAB command window. The simple function then returns the shortest result. >> simple(cos(x)^2 + sin(x)^2) %displays the following alternative simplifications in … the MATLAB command window: simplify: 1 radsimp: cos(x)^2+sin(x)^2 combine(trig): 1 factor: cos(x)^2+sin(x)^2 expand: cos(x)^2+sin(x)^2 combine: 1 convert(exp): (1/2*exp(i*x)+1/2/exp(i*x))^21/4*(exp(i*x)1/exp(i*x))^2 convert(sincos): cos(x)^2+sin(x)^2 convert(tan): (1tan(1/2*x)^2)^2/(1+tan(1/2*x)^2)^2+ 4*tan(1/2*x)^2/(1+tan(1/2*x)^2)^2 collect(x): cos(x)^2+sin(x)^2 and returns ans = 1 f = simple(f) simply returns the shortest expression found. >> f = simple(cos(x)^2+sin(x)^2)
ATLAB Lecture 5 School of Mathematical Sciences Xiamen University http∥gdjpkc.xmu.edu.cr F how=simple() returns the shortest result in the first variable and the simplification method used to achieve the result in the second variable >>f, how]=simple(cos(x)2+sin(x)2) how combine The simple function sometimes improves on the result returned by simplify, one of the simplifications that it tries. For example, when applied to the examples given for simplify, le returns a simpler(or at least shorter) result in two cases implify(f) simple(f) (/a^3+6a2+12/a+8)(1/3)(2a+)3a^3y1/3)(2+a+1)/a syms xy positive; log(x*y) log(x)+log(y) In some cases, it is advantageous to apply simple twice to obtain the effect of two different simplification functions >>f=(1/a^3+6a^2+12/a+8)^(1/3) Simple f (2*a+1)a Simple Simple f-simple( Simple f) Simple Simple f= > Simple Simple f=simple(simple(f)) Simple Simple f= 2+1/a The simple function is particularly effective on expressions involving trigonometric functions ple(f os(x)2+sin(x 2 2°cos(x)y2-sin(x)^2 3°cos(x)^2-1 cos(x) 2-sin(x) cos(x)+(-sin(x)^2)(1/2) cos(x)+I sin(x) cos(x)+i*sin(x) cos(3°acos(x) 4*x^3-3*x ◆* he findsym command Lec5-8
MATLAB Lecture 5 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Lec58 f = 1 [F, how] = simple(f) returns the shortest result in the first variable and the simplification method used to achieve the result in the second variable. >> [f, how] = simple(cos(x)^2+sin(x)^2) f = 1 how = combine The simple function sometimes improves on the result returned by simplify, one of the simplifications that it tries. For example, when applied to the examples given for simplify, simple returns a simpler (or at least shorter) result in two cases. f simplify(f) simple(f) (1/a^3+6/a^2+12/a+8)^(1/3) ((2*a+1)^3/a^3)^(1/3) (2*a+1)/a syms x y positive; log(x*y) log(x)+log(y) log(x*y) In some cases, it is advantageous to apply simple twice to obtain the effect of two different simplification functions. >> f = (1/a^3+6/a^2+12/a+8)^(1/3); >> Simple_f=simple(f) Simple_f = (2*a+1)/a >> Simple_Simple_f=simple(Simple_f) Simple_Simple_f = 2+1/a or >> Simple_Simple_f =simple(simple(f)) Simple_Simple_f = 2+1/a The simple function is particularly effective on expressions involving trigonometric functions. f simple(f) cos(x)^2+sin(x)^2 1 2*cos(x)^2sin(x)^2 3*cos(x)^21 cos(x)^2sin(x)^2 cos(2*x) cos(x)+(sin(x)^2)^(1/2) cos(x)+i*sin(x) cos(x) +i*sin(x) exp(i*x) cos(3*acos(x)) 4*x^33*x ² *The findsym Command
ATLAB Lecture 5 School of Mathematical Sciences Xiamen University http∥gdjpkc.xmu.edu.cr To determine what symbolic variables are present in an expression, use the findsym >>ffxn: gg=sin(a*t+btc): %given the symbolic expressions f and g > findsym(ff) %find the symbolic variables in ff > findsym(gg) %find the symbolic variables in gg b t 2 * Creating Abstract function >>f=sym(f(x)) % create an abstract (i. e, indeterminate)function Then f acts like and can be manipulated by the toolbox command df=(subs(f, x', x+h")-fh %to construct the first difference x h > df=(subs(f,x, x+h)-f/h df This application of sym is useful when computing Fourier, Laplace, and Z-transforms
MATLAB Lecture 5 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Lec59 To determine what symbolic variables are present in an expression, use the findsym command. >> syms a b n t x z >> c=1 >> ff= x^n; gg = sin(a*t + b+c); %given the symbolic expressions f and g >> findsym(ff) %find the symbolic variables in ff ans = n, x >> findsym(gg) %find the symbolic variables in gg ans = a, b, t ² *Creating Abstract Functions >> f = sym('f(x)') % create an abstract (i.e., indeterminate) function Then f acts like and can be manipulated by the toolbox commands. >> df = (subs(f,'x','x+h') f)/'h' %to construct the first difference ratio or >> syms x h >> df = (subs(f,x,x+h)f)/h df = (f(x+h)f(x))/h This application of sym is useful when computing Fourier, Laplace, and ztransforms