📗 Loops are used when the same task is repeated for a large number of times.
➩ If these tasks can be done simultaneously in parallel, vectorization is preferred in MATLAB: define the repeating task as a function, and apply the function to a vector or matrix.
➩ If these tasks must be done sequentially, then a for loop could be used.
➩ If these tasks are done for an unknown number of times until some condition is met, then a while loop could be used.
📗 for t = 1:n \(...f\left(t\right)...\) end repeats the function \(f\) for \(n\) times.
➩ t is the counter or index variable.
➩ In MATLAB, since i is the complex number \(\sqrt{-1}\), using i as the index variable is not recommended.
➩ In MATLAB, for loop is count controlled, meaning changing the counter variable inside the loop has no impact on the number of times the loop is repeated.
📗 for t = v \(...f\left(t\right)...\) end repeats the function \(f\) for length(v) times, one for each value in v.
➩ v = 1:n is the special case in which the set is the index set.
TopHat Quiz
📗 Approximate \(\displaystyle\sum_{i=1}^{\infty} \dfrac{1}{i^{2}} = \dfrac{\pi^{2}}{6}\). Note: sum(1 ./ (1:1000).^2) should be used instead (vectorization is faster).
📗 A function \(f\) is a contraction map if \(\left| f\left(x\right) - f\left(y\right) \right| < k \left| x - y \right|\) for some \(k \in \left[0, 1\right)\), for all \(x\) and \(y\).
📗 Every contraction mapping has a unique fixed point \(x^\star\) such that \(f\left(x^\star\right) = x^\star\).
📗 The fixed point \(x^\star\) could be found by fixed point iterations.
📗 Notes and code adapted from the course taught by Professors Beck Hasti and Michael O'Neill.
📗 You can expand all TopHat Quizzes and Discussions: .
📗 If there is an issue with TopHat during the lectures, please submit your answers on paper (include your Wisc ID and answers) or this Google form Form at the end of the lecture.