Opening the book…
Differentiation means finding the derivative of a function. In engineering, derivatives are used to describe rates of change. Velocity is the derivative of position with respect to time, and acceleration is the derivative of velocity with respect to time.
In MATLAB symbolic math, the diff function is used to differentiate symbolic expressions.
Taking a Derivative with diff
Suppose we want to differentiate the polynomial \(f(x) = x^3 + 2x^2 - 4x + 3\).
syms x f = x^3 + 2*x^2 - 4*x + 3; df = diff(f)
MATLAB returns the derivative as another symbolic expression:
df = 3*x^3 + 4*x - 4
Evaluating a Derivative at a Point
After finding the derivative, we can evaluate it at a particular x value using subs and double.
value = subs(df, x, 1); % substitute x = 1 value_numeric = double(value)
This is useful when we want the slope of a curve at one specific point.
Higher-Order Derivatives
To find a second derivative, we can call diff twice or pass a second argument to specify the order.
syms x f = x^4 - 3*x^2 + 7*x - 1; first_derivative = diff(f) second_derivative = diff(f, 2)
This page titled 14.4: Symbolic Differentiation was last modified on Tue, 30 Jun 2026 02:11:43 GMT and is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Zara Noroozi.
The book could not be loaded just now.