3.10: for Loop Incremental Development Exercise

Matlab and Octave Programming for STEM Applications · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

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

    3.10: for Loop Incremental Development Exercise
    Exercise \(\PageIndex{1}\) for Loop Incremental Development Exercise

    Write a for loop that does the following.

    Start with any existing for loop, preferably one that sums a series, such as the one in section 3.8.

    Test you code after you code each step in the process.

    1. Opens a figure for plotting.
    2. Sets the number of terms in the series to be n = 20
    3. Initializes series_sum = 0; % (Do not name the variable "sum", becuz that is a built-in MATLAB function.)
    4. Creates a for loop with index k = 1:n
    5. Computes termk = 3/(k^2)
    6. Adds termk to series_sum, and stores the result back into the series_sum variable.
    7. For each value of k, plots termk with the '*' marker.
    8. For each value of k, plots series_sum with the 's' marker.
    9. After the for loop, display the final values of termk and series_sum.
    10. Adds a title to the plot.
    Answer

    Add texts here. Do not delete this text first.


    This page titled 3.10: for Loop Incremental Development Exercise was last modified on Thu, 28 Jul 2022 16:45:59 GMT and is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Carey Smith.