计算概论代写 Python代写 Introduction to computing代写
1012CPSC111-Introduction to computing 计算概论代写 Assignment 2 – Python Practice: working with functions & Turtles As always, all your answers should use functions and every function should...
View detailsSearch the whole station
数值分析课业代写 Problem 1. Program the power method and inverse power method to compute the maximum and minimum eigenvalue/eigenvector pairs of the symmetric
Program the power method and inverse power method to compute the maximum and minimum eigenvalue/eigenvector pairs of the symmetric matrix A ∈ Rn×n.
To test your code, you can create a random eigenvalue decomposition with specified eigenvalues as follows:
Q = np.random.randn(n, n) # sample a matrix with iid N(0, 1) entries
Q = np.linalg.qr(Q)[0] # the Q factor in its QR decomposition is an
# orthogonal matrix sampled uniformly from
# the orthgonal group O(n)
Lam = np.diag(...) # set the diagonal matrix of eigenvalues manually
A = Q@Lam@Q.T # compute A from Q and Lam
This way you can fix the values of λ1 and λ2 (or 1/λn and 1/λn−1) to control the convergence rate of the (inverse) power method.
Make a plot (or several plots) of the convergence of the (inverse) power method for several different eigenvalue ratios. Since you set the eigenvalues of your test matrix A yourself, you can easily compare with the true solution. Your plot(s) should show evidence that the convergence rate is largely controlled by, e.g., λ2/λ1.
(Note: in this problem, I would like you to look at both the power method and the inverse power method. For the inverse power method, use np.linalg.lu or scipy.linalg.lu instead of your own LU decomposition to compute the LU decomposition of A. You can then use the function scipy.linalg.solve triangular to do the forward and backward solves involving your triangular factors.)
Incorporate shifts into your power method (i.e., apply the power method and inverse power method to the shifted matrix A − λI). Come up with a strategy for choosing the shift λ to accelerate the convergence of the power method. Note: the shift can vary from iteration to iteration. In general, there can be many possible strategies—you must simply come up with some strategy that reduces the overall number of iterations. However, be careful with the inverse power method: if you change the shift, you must recompute the LU decomposition used to apply (A − λI)−1 at each step.
Read about the compressed sparse row (CSR) sparse matrix format. SciPy provides a class implementing a sparse matrix using the CSR format: see scipy.sparse.csr matrix.
Set up a version of A for N = 64 using scipy.sparse.csr matrix. Next, read the documentation for the function scipy.sparse.linalg.eigsh. Use it to compute the k = 16 smallest nonzero eigenvalues and eigenvectors of A (hint: use the sigma keyword argument).
Using plt.subplot, make a 4 × 4 grid of 2D plots of each of the eigenvectors, as well as a plot of the eigenvalues that you compute.
a.
The matrix A can be interpreted as a graph. Its rows and columns are naturally identified with the nodes in the original lattice, which we think of as the graph’s vertices. There is an edge between a pair of vertices if the corresponding pair of nodes is adjacent in the lattice. Recall from lecture that A is a discretized Laplacian.
On the other hand, if we start with a graph G = (V, E), where N = |V | and V = {v1, . . . , vN} is the set of vertices and E = {(i, j) : viand vjare adjacent} is the set of edges, we can define the graph Laplacian L ∈ RN×N by:
Download a graph from:
https://sites.google.com/site/xiaomengsite/research/resources/graph-dataset
or some other website online. Load it using Python and build a CSR version of L for your graph. Next, as in Problem 3, use scipy.sparse.linalg.eigsh (note that L should be symmetric!) to compute the first k = 2 smallest nonzero eigenvalue and eigenvector pairs of L. Let u1 and u2 be these eigenvectors, and experiment with making plots of u1 and u2 to visualize the graph. Please be creative and feel free to experiment.
(Hint: the process of getting your graph into Python and building L may be annoying and require some data processing. Don’t be a hero—use a relatively simple graph to make this easy. Between a few hundred vertices and a few thousand vertices is a good target.)
b (bonus).
Compute u3 and make a 3D visualization of your graph. I recommend starting with mplot3d for 3D plotting, but feel free to contact me for more recommendations, and feel free to experiment.
Read about bipartite graphs online. An off-diagonal block of the adjaceny matrix (not the graph Laplacian matrix L!) of your graph from Problem 4 is a bipartite graph. Pick such an off-diagonal block and denote it AI,J, where I and J are the row and column indices of the block (I ∩ J = ∅).
Let m = |I| and n = |J| and p = min(m, n). Compute the singular value decomposition AI,J= UΣV T, where U ∈ Rm×p, V ∈ Rn×p, and Σ ∈ Rp×p. Do this using np.linalg.svd with full matrices=False. Make a semilogy plot of the singular values σ1, . . . , σpand observe how rapidly they decay.
更多代写:C#代码代写 槍手代考英文 英国物理Final exam 温哥华essay代写 温哥华商务英文论文写作 留学speech代写
合作平台:essay代写 论文代写 写手招聘 英国留学生代写
CPSC111-Introduction to computing 计算概论代写 Assignment 2 – Python Practice: working with functions & Turtles As always, all your answers should use functions and every function should...
View detailsPath-dependent options pricing C++ Programming with Applications to Finance 路径相关期权定价代写 The aim of this project is to create a program in C++ that can be used to price path-depende...
View detailsimage processing python Implementation (50 %) 图像处理代写 1 DoG (20 %) Use two Gaussian filters with suitable kernel sizes to to extract the license plate and remove most of the background ...
View details国外一些编程专业的作业难写吗?programming代写老师经验丰富吗? 国外programming代写 现在计算机专业越来越吃香,因为现在是互联网时代,很多岗位都需要计算机能力,因此很多大学生会选择学习相关计算机专业...
View details