3.10: for Loop Incremental Development Exercise
- Page ID
- 84393
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)
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.