例2:最简表达式的获得 msx t f=cos(x)2-sin(x) 2; Ir, how=simple(f cos (2* how= combine (5)符号表达式的分式通分( Reduction symbolic expression to common denominator 符号表达式的分式通分函数为n,d]= numden(S),此函数将符号表达 式转换为分子( Numerator)和分母( denominator)都是正系数的最佳多项 式 例:对表达式fxyy/x进行通分。 syms x f=x/y+y/x; In, d=numden(f x^2+y^2 NUMDEN Numerator and denominator of a symbolic expression IN, D]=NUMDEN(A) converts each element of a to a rational form where the numerator and denominator are relatively prime polynomials with integer coefficients (6)符号表达式的嵌套形式重写( Representation of nested symbolic expression 符号表达式的嵌套形式重写函数为 horner(S),此函数将符号表达 式转换为嵌套形式 例:对表达式f=x346x2+11x-6进行嵌套形式重写
例 2:最简表达式的获得。 syms x t f=cos(x)^2-sin(x)^2; [r,how]=simple(f) r = cos(2*x) how = combine (5)符号表达式的分式通分(Reduction symbolic expression to common denominator) 符号表达式的分式通分函数为 [n,d]=numden(S), 此函数将符号表达 式转换为分子(Numerator)和分母(denominator)都是正系数的最佳多项 式。 例:对表达式 f=x/y+y/x 进行通分。 syms x y f=x/y+y/x; [n,d]=numden(f) n = x^2+y^2 d = y*x NUMDEN Numerator and denominator of a symbolic expression. [N,D] = NUMDEN(A) converts each element of A to a rational form where the numerator and denominator are relatively prime polynomials with integer coefficients. (6) 符号表达式的嵌套形式重写(Representation of nested symbolic expression) 符号表达式的嵌套形式重写函数为 horner(S), 此函数将符号表达 式转换为嵌套形式。 例: 对表达式 f=x3+6x2+11x-6 进行嵌套形式重写
syns X fx^3+6*x^2+11*x-6; horner(f 6+(l+(+x)*x)*x HORNER Horner polynomial representation HORNER(P) transforms the symbolic polynomial P into its Horner, or nested representation 符号表达式的替换( Replacing of symbolic expression) MATLAB的符号数学工具箱提供了两个符号表达式的替换函数 subexpr和subs,可通过符号替换使表达式的输出形式简化。 subexpr函数可将表达式中重复出现的字符串用变量代替。调用格式: IY, SIGMA}= subexpr(S, SIGMA):用变量 SIGMA的值代替符号表达式S 中重复出现的字符串,Y返回替换后的结果 例:求解并化简三次方程x3+ax+1=0的符号解 t=solve( 3+a*x+1=0) Ir,sl= subexpr(t,’s”) [l/6*(-108+12*(12*a^3+81)^(1/2)^(1/3)-2*a/(-108+12*(12*a^3+81)^( 1/2)^(1/3) [-1/12*(-108+12*(12*a^3+81)(1/2)(1/3)+a/(-108+12*(12*a^3+81) (1/2))(1/3)+1/2*i*3^(12)*(1/6*(-108+12*(12*a^3+81)^(1/2)^(1/3)+2 a(-108+12*(12*a^3+81)^(1/2)(1/3)) [-1/12*(-108+12*(12*a^3+81)(1/2)(1/3)+a/(-108+12*(12*a^3+81) (1/2))(1/3)-12*1*3~(112)*(16*(-108+12*(12*a^3+81)^(1/2)^(1/3)+2 a(-108+12*(12*a^3+81)^(1/2)^(1/3) 1/6*s^(1/3)-2*as^(1/3 [-1/12*s^(1/3)+as^(1/3)+12**3^(1/2)*(1/6*^(1/3)+2*a/s^(1/3) [-1/12*s^(1/3)+a/s(1/3)-1/2*i*3^(12)*(116*s^(1/3)+2*a/s^(1/3)
syms x f=x^3+6*x^2+11*x-6; horner(f) ans = -6+(11+(6+x)*x)*x HORNER Horner polynomial representation. HORNER(P) transforms the symbolic polynomial P into its Horner, or nested, representation. 2. 符号表达式的替换(Replacing of symbolic expression) MATLAB 的符号数学工具箱提供了两个符号表达式的替换函数 subexpr 和 subs,可通过符号替换使表达式的输出形式简化。 subexpr 函数可将表达式中重复出现的字符串用变量代替。调用格式: [Y,SIGMA]=subexpr(S,SIGMA): 用变量 SIGMA 的值代替符号表达式 S 中重复出现的字符串,Y 返回替换后的结果。 例:求解并化简三次方程 x 3+ax+1=0 的符号解。 t=solve(‘x^3+a*x+1=0’) [r,s]=subexpr(t,’s’) t = [1/6*(-108+12*(12*a^3+81)^(1/2))^(1/3)-2*a/(-108+12*(12*a^3+81)^( 1/2))^(1/3)] [ -1/12*(-108+12*(12*a^3+81)^(1/2))^(1/3)+a/(-108+12*(12*a^3+81)^ (1/2))^(1/3)+1/2*i*3^(1/2)*(1/6*(-108+12*(12*a^3+81)^(1/2))^(1/3)+2 *a/(-108+12*(12*a^3+81)^(1/2))^(1/3))] [ -1/12*(-108+12*(12*a^3+81)^(1/2))^(1/3)+a/(-108+12*(12*a^3+81)^ (1/2))^(1/3)-1/2*i*3^(1/2)*(1/6*(-108+12*(12*a^3+81)^(1/2))^(1/3)+2 *a/(-108+12*(12*a^3+81)^(1/2))^(1/3))] r = [ 1/6*s^(1/3)-2*a/s^(1/3)] [ -1/12*s^(1/3)+a/s^(1/3)+1/2*i*3^(1/2)*(1/6*s^(1/3)+2*a/s^(1/3))] [ -1/12*s^(1/3)+a/s^(1/3)-1/2*i*3^(1/2)*(1/6*s^(1/3)+2*a/s^(1/3))]
-108+12*(12*a^3+81)^(12) 函数subs是用指定符号替换符号表达式中的某一特定符号,调用格 式为:R=subs(Sold,new),它可用新的符号变量new替换原来符号表达 式S中的old.当new为数值形式时,显示的结果虽然是数值,但它事实上 是符号变量。 例:分别用新变量替换表达式a+b和cos(a)+sin(b)中变量 syms a b subs(a+b, a, 4) subs(cos(a)+sin(b),{a,b},{sym( alpha"),2})%用单元数组完成不同性质 %元素的替换 ans 4+b ans - cos(alpha)+sin(2) 符号微积分 Differential and integral calculus 1.符号极限( Symbolic limit *limit(Fx,a)计算符号表达式F在x→a条件下的极限 *limit(Fa)计算符号表达式F中由默认自变量趋向于a条件下的极限; limit(F,)计算符号表达式F在默认自变量趋向于0条件下的极限; xlimit(F,x,a, right)和 I limit(Fx,a,eft)计算符号表达式F在x→a条件下 的右极限和左极限。 例:分别计算表达式m照x,m(),m(及m(+)和me syms a; imit(sin(x)x) limit(1/x, x, 0, right)
s = -108+12*(12*a^3+81)^(1/2) 函数 subs 是用指定符号替换符号表达式中的某一特定符号,调用格 式为:R=subs(S,old,new), 它可用新的符号变量 new 替换原来符号表达 式 S 中的 old. 当 new 为数值形式时,显示的结果虽然是数值,但它事实上 是符号变量。 例:分别用新变量替换表达式 a+b 和 cos(a)+sin(b)中变量。 syms a b subs(a+b,a,4) subs(cos(a)+sin(b), {a,b},{sym('alpha'),2}) %用单元数组完成不同性质 %元素的替换 ans = 4+b ans = cos(alpha)+sin(2) 三.符号微积分(Differential and integral calculus) 1. 符号极限(Symbolic limit) *limit(F,x,a) 计算符号表达式 F 在 x→a 条件下的极限; *limit(F,a) 计算符号表达式 F 中由默认自变量趋向于 a 条件下的极限; *limit(F,) 计算符号表达式 F 在默认自变量趋向于 0 条件下的极限; *limit(F,x,a,‘right’) 和limit(F,x,a,’left’) 计算符号表达式F在x→a条件下 的右极限和左极限。 例:分别计算表达式 x x x sin( ) lim →0 , ) 1 lim ( x→0+ x , ) 1 lim ( x→0 _ x 及 x x x a lim (1 ) _ + → 和 x x e − → lim syms x a; limit(sin(x)/x) limit(1/x,x,0,’right’)