14.10: Plotting Symbolic Expressions

Fundamentals of MATLAB Programming · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC-SA, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    14.10: Plotting Symbolic Expressions

    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.

    Example \(\PageIndex{1}\)

    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

    clipboard_ee7910abf3456a30e6f3f880ffa9a69b3.png

    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.

    Example \(\PageIndex{2}\)

    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

    clipboard_e6cdcfac10808ec6f20cfe2c8303dc823.png



    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.