Course policies and AI category¶
Read the Artificial Intelligence Policy and Collaboration Policy and Honor Code before starting. Assignment-specific directions control. The categories are No AI, AI permitted after independent work, and AI required.
Unless a problem says otherwise, its category is AI permitted after independent work. Spend about 30 minutes on each top-level problem without AI, solution pages, or another person’s help, stopping early if complete. You may consult lecture notes, textbooks, and nonsolution pages of the course website; bias toward those course sources. Afterward, AI and genuine collaboration, including coding together, are permitted. Everyone must contribute intellectually, understand the work, and verify it.
At the end of each top-level problem, add a concise AI and independent-work report: approximately how long the independent attempt took, how far you got, where you became stuck, any AI or collaborative help used afterward, and how you verified it. If you used no AI, say so. Do not submit prompts or transcripts. Time estimates help the instructor improve the assignment and are not a speed test.
# Load required Python libraries.
import matplotlib.pyplot as plt
import numpy as np
from scipy import linalgLinear Algebra Review¶
Exact solution¶
Solve the following system of linear equations BY HAND with exact arithmetic:
Turn in your work via Gradescope.
Solve using the inverse¶
Solve the same linear system by first inverting the matrix A and performing matrix multiplication. You should use Python and SciPy.
Tutorials and documentation: https://
docs .scipy .org /doc /scipy -1 .1 .0 /reference /tutorial /linalg .html
# Add your solution here# Add your solution here# Add your solution hereSolve using LU decomposition¶
Do the following:
Use
linalg.lu(A)to calculate , , and .Write a function to solve any linear system given the factorization and . You may not use
linalg.solvein your function. Instead, you should write loops to implement back substitution.Use your function to solve the linear system.
# You need to define the matrix A1 somewhere (or change the variable name)
P, L, U = linalg.lu(A1)
# Permutation matrix
print(P)
# Lower diagonal matrix
print(L)
# Upper diagonal matrix
print(U)[[1. 0. 0.]
[0. 0. 1.]
[0. 1. 0.]]
[[ 1. 0. 0. ]
[ 0.66666667 1. 0. ]
[-0.33333333 -0.5 1. ]]
[[ 3. 2. 1. ]
[ 0. -9.33333333 9.33333333]
[ 0. 0. 10. ]]
Tip: We discussed this algorithm in class. First write pseudocode on paper (how to translate our notes into loops, logical statements, etc.?). Once you are happy with the logic, code it up.
# Write function here.
def my_lu_solve(P, L, U, b, LOUD=True):
"""
Solves linear system Ax = b given PLU decomposition of A
Arguments:
P - N by N permutation matrix
L - N by N lower triangular matrix with 1 on diagonal
U - N by N upper triangular matrix
b - N by 1 vector
Returns:
x - N by 1 solution to linear system
"""
# Define x so this does not give an error. You can delete the line below.
x = []
# Add your solution here
return xx = my_lu_solve(P, L, U, b, LOUD=True)Solve using linalg.solve¶
# Add your solution hereEigenvalues¶
Calculate eigenvalues by hand (on paper)¶
Calculate the eigenvalues for the following matrix:
You may need to do this for a small system on an exam to characterize stationary points of an optimization problem. Hence I would like you to practice at least once on the homework.
Calculate eigenvalues using linalg.eig¶
Calculate the eigenvalues and corresponding (right) eigenvectors.
# Add your solution here# Add your solution hereDefiniteness¶
Based on your calculations above, is this matrix
positive definite
positive semi definite
negative definite
negative semi definite
indefinite or
cannot say without additional calculations?
Briefly comment to justify your answer.
Note: In this class, “briefly comment” means write a few sentences, sketch a picture, write an equation or some combination... whichever you feel is necessary to succinctly provide justification.
Singular Value Decomposition¶
TODO: Make this a separate problem (after the assignment is turned in this year).
SVD calculation using linalg.svd¶
Calculate the singular value decomposition of the following matrix using linalg.svd:
# Add your solution here# Add your solution hereCondition number¶
What is the condition number of the matrix? Calculate it two ways:
Using SVD results
Using
np.linalg.cond()
# Add your solution here# Add your solution hereLinear system¶
Consider the linear system with and
Approximately how much uncertainty can you tolerate if you want the uncertainty to be less than 10-2?
# Add your solution hereAnswer:
Make it singular¶
Do/answer the following:
Propose a change to a single entry in to make it singular.
What are the singular values and condition number after this change?
What can you say about the solution to after the change?
Answer:
Convexity¶
Please turn in via Gradescope.
Determine if the following functions are convex¶
Prove the following properties¶
Consider twice differentiable function .
Recall that is convex on if and only if
for all
PSD implies Convexity¶
Prove that if is positive semidefinite for all , then must be convex.
Convexity implies PSD¶
Prove that if is convex then must be positive semidefinite.
PD implies Strictly Convex¶
Prove that if is positive definite for all , then must be strictly convex.