>>[n, d]=numden(f% extract the numerator and denominator 前二个表达式得到期望结果 >>g=3/2 x2+2/3 x-3/5% rationalize and extract the parts 3/2*x^2+2/3*x-3/5 >>[n, d]=numden(g 45*x^2+20*x-18 >>h='(x2+3)/(2*x-1)+3*X/(x-1)% the sum of rational polynomials (x^2+3)/(2*x-1)+3*x/(x-1) >>n, d]=numden(h)% rationalize and extract x^3+5*x^2-3 在提取各部分之前,这二个表达式g和h被有理化,并变换成具有分子和分母的一个简单表 达式 >>k=sym(3/2,(2*x+1)/3: 4/x2, 3*x+4 ) try a symbolic array 3/2,(2*x+1)/3] [4Xx^2,3*x+4]
>> [n,d]=numden(f) % extract the numerator and denominator n= a*x^2 d= b-x 前二个表达式得到期望结果。 >> g= ' 3/2*x^2+2/3*x-3/5 ' % rationalize and extract the parts g= 3/2*x^2+2/3*x-3/5 >> [n,d]=numden(g) n= 45*x^2+20*x-18 d= 30 >> h= ' (x^2+3)/(2*x-1)+3*x/(x-1) ' % the sum of rational polynomials h= (x^2+3)/(2*x-1)+3*x/(x-1) >> [n,d]=numden(h) % rationalize and extract n= x^3+5*x^2-3 d= (2*x-1)*(x-1) 在提取各部分之前,这二个表达式g和h被有理化,并变换成具有分子和分母的一个简单表 达式。 >> k=sym( ' [3/2,(2*x+1)/3;4/x^2,3*x+4] ' ) % try a symbolic array k= [ 3/2,(2*x+1)/3] [4/x^2, 3*x+4] >> [n,d]=numden(k) n= [3, 2*x+1] [4, 3*x+4] d=
这个表达式k是符号数组, numden返回两个新数组n和d,其中n是分子数组,d是分母数 组。如果采用s= numden(n形式, numden仅把分子返回到变量s中 标准代数运算 很多标准的代数运算可以在符号表达式上执行,函数 symadd、 svmsub、 symlnul和 sy mdiv 为加、减、乘、除两个表达式, sy mow将一个表达式上升为另一个表达式的幂次。例如:给 定两个函数 >>f=2*x2+3*x-5% define the symbolic expression >>symadd(f, g)% find an expression for f+g 3*x^2+2*x+2 >> symsub(f, g)% find an expression for f-g ans- >> sammul(f, g)% find an expression for fg ans- (2*x^2+3*x-5)(x^2-x+7) ans-
[ 2,3] [x^2,1] 这个表达式k是符号数组,numden返回两个新数组n和d,其中n是分子数组,d是分母数 组。如果采用s=numden(f)形式,numden仅把分子返回到变量s中。 标准代数运算 很多标准的代数运算可以在符号表达式上执行,函数symadd、symsub、symlnul和symdiv 为加、减、乘、除两个表达式,sympow将一个表达式上升为另一个表达式的幂次。例如: 给 定两个函数 f = 2x + 3x −5 g = x − x + 7 2 2 >> f= ' 2*x^2+3*x-5 ' % define the symbolic expression f= 2*x^2+3*x-5 >> g= ' x^2-x+7 ' g= x^2-x+7 >> symadd(f,g) % find an expression for f+g ans= 3*x^2+2*x+2 >> symsub(f,g) % find an expression for f-g ans= x^2+4*x-12 >> symmul(f,g) % find an expression for f*g ans= (2*x^2+3*x-5)*(x^2-x+7) >> symdiv(f,g) % find an expression for f/g ans= (2*x^2+3*x-5)/(x^2-x+7) >> sympow(f, ' 3*x ' ) % find an expression for f 3* ans= (2*x^2+3*x-5)^3**