0% found this document useful (0 votes)
25 views10 pages

CS 189/289A Fall 2025 Homework 1

Uploaded by

agarwalharsh2156
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views10 pages

CS 189/289A Fall 2025 Homework 1

Uploaded by

agarwalharsh2156
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CS 189/289A Fall 2025

Homework 1
Due : Friday, September 19 at 11 : 59 pm

Deliverables. Submit a single PDF of your write-up to Gradescope HW1 Write-Up.

Start each problem on a new page.

Honor Code
Write and sign the following statement:

“I certify that all solutions in this document are entirely my own and that I have not looked at
anyone else’s solution. I have given credit to all external sources I consulted.”

Linear Algebra
1. System of equations (3 points). Consider the linear system
    
1 2 3 x 6
2 0 6   y = 8 .
 
3 6 9 z 12

How many solutions does this system have? Explain your reasoning.

1
CS 189/289A Fall 2025

2. Asymptotic powers of 2 × 2 matrices (6 points). For each matrix below, determine the
behavior of
lim M n
n→∞

Hint: Use the eigen-decomposition M = P DP −1 , where D = {λ1 , λ2 , ...} is a diagonal matrix


of the eigenvalues. What would be the formula for M n ?
 
0 1
(a) M1 = .
1 0
 
2 −5
(b) M2 = .
1/2 −7/6
 
4 −2
(c) M3 = .
1 1

2
CS 189/289A Fall 2025

3. Singular Value Decomposition (4 points). Given the matrix


 
2 −1
A=
2 2

Find a unit vector x (∥x∥ = 1) for which ∥Ax∥ is maximized.


Hint: Recall from SVD that A = U ΣV ⊤ , where A maps each right singular vector (a column
of V ) to a left singular vector (a column of U ), scaled by the corresponding singular value.
For which right singular vector does this scaling make ∥Ax∥ the largest?

3
CS 189/289A Fall 2025

4. Image Flipping (6 points). This question is a warmup to problem 4 in the coding section.
Consider a tiny 3 × 3 image represented by matrix I and the same image flipped on the Y
axis Iflip :    
x1 x2 x3 x7 x8 x9
I = x4 x5 x6  , Iflip = x4 x5 x6  .
x7 x8 x9 x1 x2 x3

(a) What is the size of the transformation matrix T that performs this flip? Hint: You can
first convert I to a 1 × 9 vector, make transformation using matrix T , and then convert
Iflip back to a 3 × 3 matrix.
(b) Construct T and verify that I × T produces Iflip .
(c) Describe an algorithm for constructing the vertical-flip transformation matrix for any
N × N matrix (either text explanation or pseudocode is acceptable). Show that I × T
produces Iflip .
(d) Describe how you would modify this algorithm to do a horizontal flip (along the X ais).

4
CS 189/289A Fall 2025

Calculus
5. Partial Derivatives (8 points). (First and second derivatives)

(a) For f (x1 , x2 ) = x31 + x32 − 3x1 x2 , find all the first and second order partial derivatives.
(b) Let f (x, y) = 4x2 + y 2 − 8xy + 4x + 6y − 10.
Find the critical points by solving
∂f ∂f
=0 and =0
∂x ∂y

simultaneously and determine which point(s) yield a minimum value.


(c) For f (x, y) = exy + x2 y, compute:
∂f ∂f
(i) ∂x and ∂y
∂2f ∂2f ∂2f
(ii) ,
∂x2 ∂y 2
, and ∂x∂y
(d) For f (x, y) = ln(x2 + y 2 + 1), compute:
∂f ∂f
(i) ∂x and ∂y
∂2f ∂2f ∂2f
(ii) ,
∂x2 ∂y 2
, and ∂x∂y

5
CS 189/289A Fall 2025

6. Recursive expression and derivatives (6 points). Suppose we have variables z1 , z2 , . . . , zn ,


w1 , . . . , wn−1 , and b1 , . . . , bn−1 ∈ R, where

zn = wn−1 zn−1 + bn−1 .

dzk
(a) Compute for k = 2, . . . , n.
dzk−1
dzn
(b) Compute .
dz1
dzn
(c) Compute . You may express your answers in terms of z1 , ..., zn , w1 , ..., wn−1 , b1 , ..., bn−1
db1

6
CS 189/289A Fall 2025

Probability
iid
7. Conditioned uniform difference (3 points). Let X, Y ∼ Unif(−1, 1). Compute

P |X − Y | ≤ 0.5 X Y > 0 .

Hint: Try drawing a 2D cartesian plane where the horizontal and vertical axes represent X
and Y respectively and each range from -1 to 1. For which quadrants is it true that XY > 0?
Within these quadrants, how can we visualize the region |X − Y | < 0.5?

7
CS 189/289A Fall 2025

8. Nearest–neighbor arc length (4 points). Suppose you select 20 i.i.d. points X1 , . . . , X20
uniformly at random on the circumference of the unit circle.

(a) Let D be the shortest arc distance from X1 to the nearest of the other 19 points. Calculate
P(D > t) where 0 ≤ t ≤ 12 .
Hint: What does the event {D > t} mean in terms of where the other 19 points can be
located relative to X1 ?
(b) Find the expected arc length (in degrees) between X1 and the point nearest to it.
Hint: The Wikipedia page on expected value of continuous variables may be helpful here.

8
CS 189/289A Fall 2025

9. Cancer screening (3 points). A medical test has sensitivity 90% and false–positive rate
3%:
P(T = 1 | C = 1) = 0.9, P(T = 1 | C = 0) = 0.03.
Suppose the disease prevalence is very low, P(C = 1) = 0.001. Compute the posterior
probability of disease given a positive test:

P(C = 1 | T = 1).

9
CS 189/289A Fall 2025

10. Follower Counts (3 points). Suppose 420 people are sitting uniformly at random around
a circle, each with a distinct number of TikTok followers. What is the expected number of
people whose follower count is higher than both their immediate neighbors?

10

Common questions

Powered by AI

The system has no solutions. The reason is that the coefficient matrix is singular as its rows are linearly dependent (third row is a combination of the first two). Upon reducing to row-echelon form, the last row becomes a zero row against a non-zero component in the augmented matrix on the right-hand side, indicating inconsistency in the system .

The first-order derivatives are \(\frac{\partial f}{\partial x} = ye^{xy} + 2xy\) and \(\frac{\partial f}{\partial y} = xe^{xy} + x^2\). The second-order derivatives are: \(\frac{\partial^2 f}{\partial x^2} = y^2e^{xy} + 2y\), \(\frac{\partial^2 f}{\partial y^2} = x^2e^{xy}\), and \(\frac{\partial^2 f}{\partial x \partial y} = e^{xy} + xye^{xy} + 2x\).

The probability is calculated by considering the regions where \(XY > 0\), which are the first and third quadrants in the coordinate plane. In these quadrants, the line \(|X - Y| = 0.5\) can be visualized as stripes narrowing the permissible area within the bounded range \(-1, 1\), reducing the total measure of the region. Calculations involve determining intersections of these lines with the areas in which \(XY > 0\).

The first-order derivatives are: \(\frac{\partial f}{\partial x_1} = 3x_1^2 - 3x_2\) and \(\frac{\partial f}{\partial x_2} = 3x_2^2 - 3x_1\). The second-order derivatives are: \(\frac{\partial^2 f}{\partial x_1^2} = 6x_1\), \(\frac{\partial^2 f}{\partial x_2^2} = 6x_2\), and \(\frac{\partial^2 f}{\partial x_1 \partial x_2} = \frac{\partial^2 f}{\partial x_2 \partial x_1} = -3\).

Applying Bayes' theorem: \(P(C = 1 | T = 1) = \frac{P(T = 1 | C = 1) P(C = 1)}{P(T = 1)}\) where \(P(T = 1) = P(T = 1 | C = 1)P(C = 1) + P(T = 1 | C = 0)P(C = 0)\). Calculate: \(P(T = 1) = 0.0009 + 0.02997 = 0.03087\). Thus, \(P(C = 1 | T = 1) = \frac{0.0009}{0.03087} \approx 0.029\). The very low prevalence skews the test's positive predictive value .

Use chain rule recursively to compute: Express \(z_k\) in terms of \(z_1\) iteratively substituting backward, \(z_k = w_{k-1}(w_{k-2}(...w_1z_1 + b_1...) + b_{k-2}) + b_{k-1}\). Derivate the expression for \(z_n\) with respect to \(z_1\), passing derivative through each multiplication step involving weights and constants, leading to a cumulative product \(w_1w_2...w_{n-1}\).

The algorithm involves creating a transformation matrix \(T\) such that for a given N, \(T\) is an N^2 x N^2 identity matrix with rows rearranged to map each entry in the original vectorized format of the matrix to its vertically flipped position. Populate \(T\) where \(T[i, j] = 1\) if the element in the ith position of the vector should end up in the jth position after flip, else \(T[i, j] = 0\).

Convert the 3x3 image matrix \(I\) to a 1x9 vector \([x_1, x_2, ..., x_9]\), then construct a 9x9 transformation matrix \(T\) that swaps the necessary elements to achieve a Y-axis flip. Specifically, \(T\) should map each element to its corresponding position in \(Iflip\), yielding \([x_7, x_8, x_9, x_4, x_5, x_6, x_1, x_2, x_3]\) when applied to \(I\). This involves placing ones in appropriate positions along each row of \(T\) to ensure correct swaps in the result .

As \(n \to \infty\), for \(M_1\), which swaps elements, the eigenvalues are \(1\) and \(-1\). The eigenvectors indicate repeated swaps between entries, remaining bounded in magnitude, thus \(M_1^n\) will cycle between two fixed states indefinitely. This oscillatory behavior is due to the nature of its eigenvalues .

The expected arc length for 20 points on the unit circle is computed as \(\frac{360}{20} = 18\) degrees due to symmetry and uniform distribution, with each segment between successive points approximating one-20th of the circle's circumference. The expected measure ensures optimal spacing under identical independent distribution .

You might also like