MATLAB - Algebra
MATLAB - Algebra
Example-12:
% 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)
Factorization and Simplification of Algebraic Expressions
Example-13: The factor function factorizes an expression and the simplify function simplifies an
expression.
syms x
syms y
factor(x^3 - y^3)
factor([x^2-y^2,x^3+y^3])
simplify((x^4-16)/(x^2-4))
ans = (x - y)*(x^2 + x*y + y^2)
ans =[ (x - y)*(x + y), (x + y)*(x^2 - x*y + y^2)]
ans = x^2+4