need help with computational physics hw for python
Posted: Wed May 04, 2022 1:10 pm
need help with computational physics hw for python
Exercise 6.8 In this exercise you'll write a program to calculate the eigenvalues and eigenvectors of a real symmetric matrix using the QR algorithm. The first challenge is to write a program that finds the QR decomposition of a matrix. Then we'll use that decomposition to find the eigenvalues. Refer to the question in your textbook for the complete details to this exercise. b) Write a Python function that takes as its argument a real square matrix A and returns the two matrices Q and R that form its QR decomposition. As a test case, try out your function on the matrix listed in this problem description from your textbook. Check the results by multiplying Q and R together to recover the original matrix A again. You can use the numpy function dot() to perform matrix multiplication. :#Type your code here /20pts. c) Using your function, write a complete program to calculate the eigenvalues and eigenvectors of a real symmetric matrix using the QR algorithm. Continue the calculation until the magnitude of every off-diagonal element of the matrix is smaller than 106. Test your program on the example matrix above. You should find that the eigenvalues are 1, 21, -3, and-8. Out the eigenvectors and eigenvalues. :#Type your code here /20pts. d) Verify that your eigenvalues and eigenvectors satisfy the eigenvector equation: Av = λv # Type code here /10pts. e) Verify your eigenvectors and eigenvalues using the numpy.linalg function eigh(). # Type code here /10pts.
Exercise 6.8 In this exercise you'll write a program to calculate the eigenvalues and eigenvectors of a real symmetric matrix using the QR algorithm. The first challenge is to write a program that finds the QR decomposition of a matrix. Then we'll use that decomposition to find the eigenvalues. Refer to the question in your textbook for the complete details to this exercise. b) Write a Python function that takes as its argument a real square matrix A and returns the two matrices Q and R that form its QR decomposition. As a test case, try out your function on the matrix listed in this problem description from your textbook. Check the results by multiplying Q and R together to recover the original matrix A again. You can use the numpy function dot() to perform matrix multiplication. :#Type your code here /20pts. c) Using your function, write a complete program to calculate the eigenvalues and eigenvectors of a real symmetric matrix using the QR algorithm. Continue the calculation until the magnitude of every off-diagonal element of the matrix is smaller than 106. Test your program on the example matrix above. You should find that the eigenvalues are 1, 21, -3, and-8. Out the eigenvectors and eigenvalues. :#Type your code here /20pts. d) Verify that your eigenvalues and eigenvectors satisfy the eigenvector equation: Av = λv # Type code here /10pts. e) Verify your eigenvectors and eigenvalues using the numpy.linalg function eigh(). # Type code here /10pts.