Labsheet 4 (Derivatives)
Labsheet 4 (Derivatives)
Objective
This lab will guide you through finding derivatives of functions using MATLAB’s
Symbolic Math Toolbox. You’ll solve examples and complete exercises to reinforce
your understanding of derivatives.
MATLAB Commands to Know
syms — Define symbolic variables.
diff — Compute the derivative of a function.
Getting Started
1. Open MATLAB.
2. Ensure the Symbolic Math Toolbox is installed.
3. Use syms to declare symbolic variables for your functions.
1. Basic Syntax for Derivatives in MATLAB
To find the derivative of a function f(x) with respect to x:
syms x
f = <your function>;
df = diff(f, x);
To find higher-order derivatives, specify the order:
d2f = diff(f, x, 2); % Second derivative of f with respect to x
2. Examples
Example 1: First Derivative
syms x
f = x^3 + 5*x^2 - 2*x + 7;
df = diff(f, x);
disp(df);