Simplify these symbolic expressions:
syms x a b c simplify(sin(x)^2 + cos(x)^2) simplify(exp(c*log(sqrt(a+b))))
ans = 1 ans = (a + b)^(c/2)
simplify for this symbolic
matrix. When the input argument is a vector or matrix,
to find a simpler form of each element of the vector or matrix.
syms x M = [(x^2 + 5*x + 6)/(x + 2), sin(x)*sin(2*x) + cos(x)*cos(2*x); (exp(-x*i)*i)/2 - (exp(x*i)*i)/2, sqrt(16)]; simplify(M)
ans = [ x + 3, cos(x)] [ sin(x), 4]
Try to simplify this expression. By default,
not combine powers and logarithms because combining them is not valid
for generic complex values.
syms x s = (log(x^2 + 2*x + 1) - log(x + 1))*sqrt(x^2); simplify(s)
ans = -(log(x + 1) - log((x + 1)^2))*(x^2)^(1/2)
To apply the simplification rules that let the
combine powers and logarithms, set
simplify(s, 'IgnoreAnalyticConstraints', true)
ans = x*log(x + 1)
Simplify this expression:
syms x f = ((exp(-x*i)*i)/2 - (exp(x*i)*i)/2)/(exp(-x*i)/2 + ... exp(x*i)/2); simplify(f)
ans = -(exp(x*2i)*1i - 1i)/(exp(x*2i) + 1)
simplify uses one internal
simplification step. You can get different, often shorter, simplification
results by increasing the number of simplification steps:
simplify(f,'Steps',10) simplify(f,'Steps',30) simplify(f,'Steps',50)
ans = 2i/(exp(x*2i) + 1) - 1i ans = ((cos(x) - sin(x)*1i)*1i)/cos(x) - 1i ans = tan(x)
If you are unable to return the desired result, try alternate simplification functions. See Choose Function to Rearrange Expression.
Attempt to separate real and imaginary parts
of an expression by setting the value of
syms x f = (exp(x + exp(-x*i)/2 - exp(x*i)/2)*i)/2 -... (exp(- x - exp(-x*i)/2 + exp(x*i)/2)*i)/2; simplify(f, 'Criterion','preferReal', 'Steps', 100)
ans = sin(sin(x))*cosh(x) + cos(sin(x))*sinh(x)*1i
Criterion is not set to
simplify returns a shorter result but the
real and imaginary parts are not separated.
ans = sin(sin(x) + x*1i)
When you set
the simplifier disfavors expression forms where complex values appear
inside subexpressions. In nested subexpressions, the deeper the complex
value appears inside an expression, the least preference this form
of an expression gets.
Attempt to avoid imaginary terms in exponents
Show this behavior by simplifying a complex symbolic expression
with and without setting
Criterion is set to
simplify places the imaginary term outside
expr = sym(i)^(i+1); withoutPreferReal = simplify(expr,'Steps',100)
withoutPreferReal = (-1)^(1/2 + 1i/2)
withPreferReal = simplify(expr,'Criterion','preferReal','Steps',100)
withPreferReal = exp(-pi/2)*1i
Simplify expressions containing symbolic units
of the same dimension by using
u = symunit; expr = 300*u.cm + 40*u.inch + 2*u.m; expr = simplify(expr)
expr = (3008/5)*[cm]
simplify automatically chooses the unit
to rewrite into. To choose a specific unit, use
S— Input expression
Input expression, specified as a symbolic expression, function, vector, or matrix.
Specify optional comma-separated pairs of
Name is the argument
Value is the corresponding
Name must appear
inside single quotes (
You can specify several name and value pair
arguments in any order as
'Seconds',60limits the simplification process to 60 seconds.
'Criterion'— Simplification criterion
Simplification criterion, specified as the comma-separated pair
'Criterion' and one of these character
|Use the default (internal) simplification criteria.|
|Favor the forms of |
'IgnoreAnalyticConstraints'— Simplification rules
Simplification rules, specified as the comma-separated pair
'IgnoreAnalyticConstraints' and one
of these values.
|Use strict simplification rules. |
|Apply purely algebraic simplifications to an expression. |
'Seconds'— Time limit for the simplification process
Time limit for the simplification process, specified as the
comma-separated pair consisting of
a positive value that denotes the maximal time in seconds.
'Steps'— Number of simplification steps
Number of simplification steps, specified as the comma-separated
pair consisting of
'Steps' and a positive value
that denotes the maximal number of internal simplification steps.
Note that increasing the number of simplification steps can slow down
simplify(S,'Steps',n) is equivalent to
n is the number of simplification steps.
Simplification of mathematical expression is not a clearly defined subject. There is no universal idea as to which form of an expression is simplest. The form of a mathematical expression that is simplest for one problem might be complicated or even unsuitable for another problem.
When you use
log(a) + log(b) = log(a·b) for all values of a and b. In particular, the following equality is valid for all values of a, b, and c:
(a·b)c = ac·bc.
log(ab) = b·log(a) for all values of a and b. In particular, the following equality is valid for all values of a, b, and c:
(ab)c = ab·c.
If f and g are standard mathematical functions and f(g(x)) = x for all small positive numbers, f(g(x)) = x is assumed to be valid for all complex values of x. In particular:
log(ex) = x
asin(sin(x)) = x, acos(cos(x)) = x, atan(tan(x)) = x
asinh(sinh(x)) = x, acosh(cosh(x)) = x, atanh(tanh(x)) = x
Wk(x·ex) = x for all values of k