12.10: Common Mistakes and Best Practices

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.

    12.10: Common Mistakes and Best Practices

    Topic

    Common Mistake

    Better Practice

    Polynomial vectors

    Forgetting zeros for missing powers

    Include every coefficient from highest degree to constant term

    Interpolation

    Using interpolation outside the data range without thinking

    Recognize that this becomes extrapolation and may be unreliable

    Curve fitting

    Choosing the highest polynomial degree automatically

    Choose a model that is simple and physically reasonable

    polyfit/polyval

    Finding coefficients but forgetting to evaluate them

    Use polyfit to fit, then polyval to predict or plot

    Anonymous functions

    Using ^, *, / when arrays are expected

    Use .^, .*, ./ for element-by-element operations

    trapz

    Using too few points

    Use enough points to approximate the curve well

    fzero

    Expecting it to find all roots

    Use multiple guesses or intervals for multiple roots


    This page titled 12.10: Common Mistakes and Best Practices was last modified on Tue, 30 Jun 2026 02:11:52 GMT and is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Zara Noroozi.