创建脚本文件并键入以下代码 -
% first of all load the package, make sure its installed. pkg load symbolic % make symbols module available symbols % define symbolic variables x = sym ('x'); y = sym ('y'); z = sym ('z'); % expanding equations expand((x-5)*(x+9)) expand((x+2)*(x-3)*(x-5)*(x+7)) expand(Sin(2*x)) expand(Cos(x+y)) % collecting equations collect(x^3 *(x-7), z) collect(x^4*(x-3)*(x-5), z)
运行文件时,会显示以下结果 -
ans = -45.0+x^2+(4.0)*x ans = 210.0+x^4-(43.0)*x^2+x^3+(23.0)*x ans = sin((2.0)*x) ans = cos(y+x) ans = x^(3.0)*(-7.0+x) ans = (-3.0+x)*x^(4.0)*(-5.0+x)
代数表达式的因式分解和简化
因子函数将表达式分解,简化函数简化表达式。 以下示例演示了这一概念 -
示例
创建脚本文件并键入以下代码 -
syms x syms y factor(x^3 - y^3) f = factor(y^2*x^2,x) simplify((x^4-16)/(x^2-4))
执行上面示例代码,得到以下结果 -
Trial>> factorization ans = [ x - y, x^2 + x*y + y^2] f = [ y^2, x, x] ans = x^2 + 4