📗 A curve can be the graph of a function described by \(y = f\left(x\right)\), or the trace of a moving point, in which the movement of the point is described by its position \(\left(f_{x}\left(t\right), f_{y}\left(t\right)\right)\) at time \(t\).
📗 A curve is plotted using a large number of line segments.
➩ To plot \(y = f\left(x\right)\) from \(x = x_{1}\) to \(x = x_{n}\), find \(x_{1} < x_{2} < x_{3} < ... < x_{n}\) and use lines to connect the following points, \(\left(x_{1}, f\left(x_{1}\right)\right), \left(x_{2}, f\left(x_{2}\right)\right), \left(x_{3}, f\left(x_{3}\right)\right), ..., \left(x_{n} f\left(x_{n}\right)\right)\).
➩ To plot \(\left(f_{x}\left(t\right), f_{y}\left(t\right)\right)\) from \(t = t_{1}\) to \(t_{n}\), find \(t_{1} < t_{2} < t_{3} < ... < t_{n}\) and use lines to connect the following points, \(\left(f_{x}\left(t_{1}\right), f_{y}\left(t_{1}\right)\right), \left(f_{x}\left(t_{2}\right), f_{y}\left(t_{2}\right)\right), \left(f_{x}\left(t_{3}\right), f_{y}\left(t_{3}\right)\right), ..., \left(f_{x}\left(t_{n}\right), f_{y}\left(t_{n}\right)\right)\)
📗 Suppose \(x, y\) are vectors of length \(n\), plot(x, y) plots line segments connecting \(\left(x_{1}, y_{1}\right), \left(x_{2}, y_{2}\right), ..., \left(x_{n}, y_{n}\right)\).
➩ For example, define x = 0:0.01:1 and use plot(x, f(x)) to plot \(f\left(x\right)\) between \(0\) and \(1\) with a partition of size \(100\).
➩ Another example, define t = 0:0.01:1 and use plot(fx(t), fy(t)) to plot \(\left(f_{x}\left(t\right), f_{y}\left(t\right)\right)\) between \(0\) and \(1\) with a partition of size \(100\).
📗 Suppose \(x, y, z\) are vectors of length \(n\).
📗 plot3(x, y, z, s) plots the lines in 3D connecting \(\left(x_{1}, y_{1}, z_{1}\right), \left(x_{2}, y_{2}, z_{2}\right), ..., \left(x_{n}, y_{n}, z_{n}\right)\), with specs \(s\).
📗 A surface can be a graph of a function described \(z = f\left(x, y\right)\), or the trace of a moving point, in which the movement of the point is described by its position \(\left(f_{x}\left(s, t\right), f_{y}\left(s, t\right), f_{z}\left(s, t\right)\right)\).
📗 A surface is plotted using a large number of faces, usually triangles, but in MATLAB, four sided polygons.
📗 Suppose \(x, y, z\) are matrices representing points on the surface.
➩ contour(x, y, z, n) plots \(n\) contours of the surface, and contour3(x, y, z, n) plots them in 3D.
➩ mesh(x, y, z) plots the surface mesh.
➩ surf(x, y, z) plots the surface.
📗 If \(x\) and \(y\) are omitted, the \(x\) and \(y\) coordinates are assumed to be the column and row indices of the elements in \(z\).
TopHat Quiz
📗 Plot a unit height pyramid centered at \(\left(2, 2\right)\).
➩ A: surf([1 1 1; 1 0 1; 1 1 1]
➩ B: surf([0 0 0; 0 1 0; 0 0 0]
➩ C: surf([0 1 0; 0 1 0; 0 1 0]
➩ D: surf([0 0 0; 1 1 1; 0 0 0]
TopHat Quiz
📗 Plot \(z = x + 2 y\) for \(x = y = \begin{bmatrix} 1 & 2 & 3 \end{bmatrix}\) using surf(x + 2 * y).
➩ A: x = repmat([1 2 3], [3 1]); y = repmat([1 2 3]', [1 3])
➩ B: x = repmat([1 2 3]', [1 3]); y = repmat([1 2 3], [3 1])
➩ C: x = repmat([1 2 3], [1 3]); y = repmat([1 2 3]', [3 1])
➩ D: x = repmat([1 2 3]', [3 1]); y = repmat([1 2 3]', [1 3])
📗 [x, y] = meshgrid(u, v) creates x = repmat(u, [length(v) 1]) and y = repmat(v', [1 length(u)]). The matrices \(x, y\) then can be used to plot the surface \(z = f\left(x, y\right)\) using surf(x, y, f(x, y)).
📗 [x, y, z] = sphere() and [x, y, z] = cylinder() create meshes of a unit sphere and a unit cylinder. The surface then can be plotted using surf(x, y, z).
📗 Under "PLOTS" tab, many other plots can be created based on a matrix.
TopHat Quiz
📗 Plot \(z = x^{2} + y^{2}\) for \(x = y = \begin{bmatrix} -2 & -1 & 0 & 1 & 2 \end{bmatrix}\) using [x, y] = meshgrid(-2:2, -2:2)
➩ A: surf(x, y, x .^ 2 + y .^ 2)
➩ B: surf(x, y, x ^ 2 + y ^ 2)
➩ C: surf(x, y, x' * x + y' * y)
➩ D: surf(x, y, x * x' + y * y')
📗 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.