MATLAB's symbolic math toolbox provides powerful capabilities for performing algebraic manipulations, solving equations, and working with symbolic expressions. This feature extends MATLAB's numerical computing prowess to handle symbolic mathematics efficiently.
To use symbolic math in MATLAB, you first need to create symbolic variables or expressions. This is done using the sym
function:
syms x y
f = x^2 + 2*x*y + y^2;
In this example, x
and y
are declared as symbolic variables, and f
is a symbolic expression.
Use the simplify
function to simplify symbolic expressions:
g = (x^2 - y^2) / (x - y);
simplified_g = simplify(g)
% Output: simplified_g = x + y
The solve
function is used to solve symbolic equations:
eqn = x^2 + 5*x + 6 == 0;
solution = solve(eqn, x)
% Output: solution = [-3; -2]
Perform symbolic differentiation with diff
and integration with int
:
f = x^3 + 2*x^2 + 5*x + 1;
df = diff(f, x) % Differentiate f with respect to x
integral_f = int(f, x) % Integrate f with respect to x
Calculate limits using the limit
function:
lim = limit(sin(x)/x, x, 0)
% Output: lim = 1
Compute Taylor series expansions with taylor
:
t = taylor(exp(x), 'Order', 5)
% Output: t = 1 + x + x^2/2 + x^3/6 + x^4/24 + O(x^5)
vpa
(Variable Precision Arithmetic) for numerical approximations of symbolic results.Symbolic math in MATLAB integrates seamlessly with other toolboxes and features:
By mastering symbolic math in MATLAB, you can tackle complex mathematical problems, perform advanced analyses, and enhance your problem-solving capabilities across various domains of engineering and scientific computing.