Opening the book…
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.
- Opens a figure for plotting.
- Sets the number of terms in the series to be n = 20
- Initializes series_sum = 0; % (Do not name the variable "sum", becuz that is a built-in MATLAB function.)
- Creates a for loop with index k = 1:n
- Computes termk = 3/(k^2)
- Adds termk to series_sum, and stores the result back into the series_sum variable.
- For each value of k, plots termk with the '*' marker.
- For each value of k, plots series_sum with the 's' marker.
- After the for loop, display the final values of termk and series_sum.
- 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.
The book could not be loaded just now.