Prev: W1 Next: W3

📗 Tuesday lectures: 4:00 to 4:50, Zoom, TopHat: Link (or Google Form: Form if TopHat not working). MATLAB.
📗 Programming Homework: P1

Slide:


# Scalar Operations

x + y is \(x + y\), x - y is \(x - y\).
x * y is \(x y\), x / y or y \ x are \(\dfrac{x}{y}\).
x ^ y is \(x^{y}\), sqrt(x) is \(\sqrt{x}\).
exp(x) is \(e^{x}\), log(x) is natural log or \(\ln\left(x\right)\), log10(x) is \(\log_{10}\left(x\right)\).
sin(x) is \(\sin\left(x\right)\) in radians, sind(x) is \(\sin\left(x\right)\) in degrees, asin(y) is \(arcsin\left(y\right)\) in radians, asind(y) is \(arcsin\left(y\right)\) in degrees. Same for cos(x) and tan(x).
TopHat Discussion
📗 Are you joining the lecture in person or on Zoom?
➩ A: I don't know
➩ B: In person
➩ C: Zoom
➩ D: Both

# Integer Operations

round(x) is rounding \(x\) to nearest integer.
floor(x) is \(\left \lfloor{x}\right \rfloor\), largest integer \(\leq x\), ceil(x) is \(\left \lceil{x}\right \rceil\), smallest integer \(\geq x\).
mod(x, y) is \(x \mod y\), \(x\) modulo \(y\), the remainder when \(x\) is divided by \(y\), integer division: x % y does not work in MATLAB.

# Numerical Instability

📗 The number of decimal places that is displayed can be changed.
📗 The number of decimal places that can be stored is fixed.
➩ \(\pi, e, \sqrt{2}\) etc are approximate values (accurate up to 16 decimal places).
➩ Underflow may occur: numbers that are too close to \(0\) are stored as 0.
➩ Overflow may occur: numbers that are too large are stored as Inf.
TopHat Quiz
📗 10 ^ 309
➩ A: \(3090\) 
➩ B: \(1e+309\)
➩ C: \(1.0000e+309\)
➩ D: \(\text{\;Inf\;}\)

TopHat Quiz
📗 10 ^ -309
➩ A: \(-3090\) 
➩ B: \(1e-309\)
➩ C: \(1.0000e-309\)
➩ D: \(0\)

TopHat Quiz
📗 \(1\)
➩ A: (1 + 10^-16 - 1) * 10^16
➩ B: (1 - 1 + 10^-16) * 10^16
➩ C: (10^-16 + 1 - 1) * 10^16
➩ D: (-1 + 10^-16 + 1) * 10^16


# Vector Multiplication

📗 \(\begin{bmatrix} a \\ b \end{bmatrix} \odot \begin{bmatrix} c \\ d \end{bmatrix} = \begin{bmatrix} a c \\ b d \end{bmatrix}\) is the element-wise product.
📗 \(\begin{bmatrix} a \\ b \end{bmatrix} \cdot \begin{bmatrix} c \\ d \end{bmatrix} = \begin{bmatrix} a & b \end{bmatrix} \begin{bmatrix} c \\ d \end{bmatrix} = a c + b d\) is the inner product, also called the dot product.
📗 \(\begin{bmatrix} a \\ b \end{bmatrix} \otimes \begin{bmatrix} c \\ d \end{bmatrix} = \begin{bmatrix} a \\ b \end{bmatrix} \begin{bmatrix} c & d \end{bmatrix} = \begin{bmatrix} a c & a d \\ b c & b d \end{bmatrix}\) is the outer product.
📗 Suppose \(M\) and \(W\) are two row vectors having the same size, and \(c\) is a scalar.
M + W and M - W are element-wise and also vector addition and subtraction.
M .* W is the element-wise product \(M \odot W\).
M * W' or dot(M, W) are the inner product \(M \cdot W = M W^\top\).
M' * W is the outer product \(M \otimes W = M^\top W\).
M .^ W and M .^ c are element-wise exponentiation.
TopHat Quiz
📗 \(2, 6, 12, 20, 30, 42, 56, 72\)
➩ A: (1:8)' * (2:9)
➩ B: (1:8) * (2:9)'
➩ C: (1:8) * (2:9)
➩ D: (1:8) .* (2:9)

TopHat Quiz
📗 \(1, 2, 4, 8, 16, 32, 64, 128\)
➩ A: (0:7) ^ 2
➩ B: (0:7) .^ 2
➩ C: 2 ^ (0:7)
➩ D: 2 .^ (0:7)


# General Vector Operations

📗 Most of the built-in operations are element-wise when applied to vectors.
sqrt([a b c]) is \(\begin{bmatrix} \sqrt{a} & \sqrt{b} & \sqrt{c} \end{bmatrix}\).
[a b c] .^ 0.5 is also \(\begin{bmatrix} \sqrt{a} & \sqrt{b} & \sqrt{c} \end{bmatrix}\).
[a b c] ^ 0.5 results in an error.
TopHat Quiz
📗 \(1, 0, -1, 0, 1, 0, -1, 0\)
➩ A: round(sind((0:7) * 180))
➩ B: round(cosd((0:7) * 180))
➩ C: round(sind((0:7) * 90))
➩ D: round(cosd((0:7) * 90))


# Matrix Multiplication

📗 \(\begin{bmatrix} a & b \\ c & d \end{bmatrix} \odot \begin{bmatrix} e & f \\ g & h \end{bmatrix} = \begin{bmatrix} a e & b f \\ c g & d h \end{bmatrix}\) is the element-wise product.
📗 \(\begin{bmatrix} a & b \\ c & d \end{bmatrix} \begin{bmatrix} e \\ f \end{bmatrix} = \begin{bmatrix} a e + b f \\ c e + d f \end{bmatrix}\) and \(\begin{bmatrix} e & f \end{bmatrix} \begin{bmatrix} a & b \\ c & d \end{bmatrix} = \begin{bmatrix} e a + f c & e b + f d \end{bmatrix}\) and \(\begin{bmatrix} a & b \\ c & d \end{bmatrix} \begin{bmatrix} e & f \\ g & h \end{bmatrix} = \begin{bmatrix} a e + b g & a f + b h \\ c e + d g & c f + d h \end{bmatrix}\) are matrix products.
📗 Suppose \(M\) and \(W\) are two matrices, and \(c\) is a scalar.
M + W and M - W are element-wise and also matrix addition and subtraction.
M .* W, when \(M\) and \(W\) have the same size, is the element-wise product \(M \odot W\), and M * W, when the number of columns of \(M\) is the same as the number of rows of \(W\), is the matrix product \(M W\).
M ./ W and W .\ M are element-wise, and M / W and W \ M find the matrix \(X\) such that \(M X = W\), the solution of a system of linear equations.
M .^ W and M .^ c are element-wise, and M ^ c is matrix exponentiation, for example, M ^ 2 is M * M.
TopHat Quiz
📗 What is the second column of \(\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix}\) ?
m = [1 2 3; 4 5 6; 7 8 9]
📗 \(\begin{bmatrix} 2 \\ 5 \\ 8 \end{bmatrix}\)
➩ A: m * [0 1 0]
➩ B: m * [0; 1; 0]
➩ C: [0 1 0] * m
➩ D: [0; 1; 0] * m

TopHat Quiz
📗 What is the row 2 column 3 entry of \(\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix}\) ?
m = [1 2 3; 4 5 6; 7 8 9]; ei = [0; 1; 0]; ej = [0; 0; 1]
📗 \(6\)
➩ A: ei' * m * ej
➩ B: ej' * m * ei
➩ C: ei' * ej * m
➩ D: m * ei * ej'


# General Matrix Operations

📗 Most of the built-in operations are element-wise when applied to matrices.
sqrt([a b; c d]) is \(\begin{bmatrix} \sqrt{a} & \sqrt{b} \\ \sqrt{c} & \sqrt{d} \end{bmatrix}\).
[a b; c d] .^ 0.5 is also \(\begin{bmatrix} \sqrt{a} & \sqrt{b} \\ \sqrt{c} & \sqrt{d} \end{bmatrix}\).
[a b; c d] ^ 0.5 is the actual square root of the matrix, it finds a matrix \(\begin{bmatrix} e & f \\ g & h \end{bmatrix}\) such that \(\begin{bmatrix} e & f \\ g & h \end{bmatrix} \begin{bmatrix} e & f \\ g & h \end{bmatrix} = \begin{bmatrix} a & b \\ c & d \end{bmatrix}\).


📗 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.





Last Updated: March 03, 2025 at 12:52 AM