Opening the book…
To plot symbolic expressions, use fplot. This function is convenient because you do not need to manually create an array of x values. MATLAB samples the function over the plotting interval.
Plotting a function
syms x
anExpr = x^3 + 3*x^2 - 2;
fplot(anExpr, [-5 5])
grid on
xlabel('x')
ylabel('f(x)')
title('Symbolic Function Plot')
Solution

If no interval is specified, fplot uses a default range. To choose a specific domain, provide a two-element vector.
fplot(anExpr, [-5 5])
11.2 Plotting a Function and Its Derivative
A useful way to understand derivatives is to plot a function and its derivative on the same graph.
Plotting a function and its derivative
syms x
f = x^3 - 4*x + 1;
df = diff(f);
fplot(f, [-3 3])
hold on
fplot(df, [-3 3])
grid on
xlabel('x')
legend('f(x)', 'df/dx')
title('Function and Derivative')
hold off
Solution

This page titled 14.10: Plotting Symbolic Expressions 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.