For loops - Your turn#
Part 1#
Write a script to compute the sum of all components of a vector. Your script should work regardless of the size of the vector. Test your script with using the following vector: \(\vec{v} = \begin{bmatrix} 2 & 1.1 & -3 & 5.2 & 4.7 \end{bmatrix} \)
Note: Using built-in functions like np.sum()
will not earn credit!
# TODO: Write your solution below
Part 2#
Define and plot the function \(y(x) = |x|\) for \(x\) ranging between \(-1\) and \(1\), with \(x\) coordinates spaced by \(0.05\).
Note: Using built-in functions like np.absolute()
will not earn credit!
# TODO: Write your solution below
Exporting your work#
When you’re ready, the easiest way to export the notebook is to File > Print
it and save it as a PDF.
Remove any excessively long, unrelated outputs first by clicking the arrow → next to the output box and then Show/hide output
.
Obviously don’t obscure any necessary output or graphs!