-2

enter image description here

How can I create Matrix P consisting of three eigenvector columns by using a double nested loop.

from sympy.matrices import Matrix, zeros
from sympy import pprint

A = Matrix([[6,2,6], [2,6,6], [6,6,2]])
ew_A = A.eigenvals()
ev_A = A.eigenvects()
pprint(ew_A)
pprint(ev_A)


# Matrix P
(n,m) = A.shape 
P = TODO  # Initialising

# "filling Matrix P with ... 
for i in TODO: 
    for j in TODO:
        P[:,i+j] = TODO
    
## Calculating Diagonalmatrix
D= P**-1*P*A

Thanks so much in Advance

chaos
  • 5
  • 5
  • Please revise your post so that it does not contain [images of code](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors-when-asking-a-question). (Post code in a text format instead.) – BrokenBenchmark Apr 16 '22 at 23:01

1 Answers1

0

Finding the eigenvalues of a matrix, or diagonalizing it, is equivalent to finding the zeros of a polynomial with a degree equal to the size of the matrix. So in your case diagonalizing a 3x3 matrix is equivalent to finding the zeros of a 3rd degree polynomial. Maybe there is a simple algorithm for that, but mathematicians always go for the general case.

And in the general case you can show that there is no terminating algorithm for finding the zeros of a 5th-or-higher degree polynomial (that is called Galois theory), so there is also no simple "triple loop" algorithm for matrices of size 5x5 and higher. Eigenvalue software works by an iterative approximation algorithm, so that is a "while" loop around some finite loops.

This means that your question has no answer in the general case. In the 3x3 case maybe, but even that is not going to be terribly simple.

Victor Eijkhout
  • 5,088
  • 2
  • 22
  • 23
  • Thanks for your answer! How can i create Matrix P from eigenvectors without using double loops, (since its complicated) ? – chaos Apr 19 '22 at 06:53
  • Read a book. There are many algorithms. I believe the "implicitly shifted QR" algorithm is the best. – Victor Eijkhout Apr 19 '22 at 12:36