Ticket #3794: eigenfunctions-doc.patch
| File eigenfunctions-doc.patch, 4.2 kB (added by jason, 5 months ago) |
|---|
-
a/const/const.tex
old new 1487 1487 1488 1488 How do you compute eigenvalues and eigenvectors using \sage? 1489 1489 1490 \sage included both in the \code{eigenspaces} command, the output of which has 1491 several components, corresponding to the different eigenvalues. 1492 1493 \begin{verbatim} 1494 sage: MS = MatrixSpace(QQ, 3, 3) 1495 sage: A = MS([[1,1,0],[0,2,0],[0,0,3]]) 1490 \sage has a full range of functions for computing eigenvalues and both 1491 left and right eigenvectors and eigenspaces. If our matrix is $A$, then 1492 \code{eigenmatrix_right} (\code{eigenmatrix_left}) command also 1493 gives matrices $D$ and $P$ such that $AP=PD$ ($PA=DP$). 1494 1495 \begin{verbatim} 1496 sage: A = matrix(QQ, [[1,1,0],[0,2,0],[0,0,3]]) 1496 1497 sage: A 1497 1498 [1 1 0] 1498 1499 [0 2 0] 1499 1500 [0 0 3] 1500 sage: A.eigenspaces() 1501 sage: A.eigenvalues() 1502 [3, 2, 1] 1503 sage: A.eigenvectors_right() 1504 [(3, [ 1505 (0, 0, 1) 1506 ], 1), (2, [ 1507 (1, 1, 0) 1508 ], 1), (1, [ 1509 (1, 0, 0) 1510 ], 1)] 1511 sage: A.eigenspaces_right() 1501 1512 [ 1502 1513 (3, Vector space of degree 3 and dimension 1 over Rational Field 1503 1514 User basis matrix: 1504 1515 [0 0 1]), 1505 1516 (2, Vector space of degree 3 and dimension 1 over Rational Field 1506 1517 User basis matrix: 1507 [ 01 0]),1518 [1 1 0]), 1508 1519 (1, Vector space of degree 3 and dimension 1 over Rational Field 1509 1520 User basis matrix: 1510 [ 1 -10])1521 [1 0 0]) 1511 1522 ] 1512 sage: A = MS([[1,1,0],[0,1,0],[0,0, 2]]) 1513 sage: A 1514 [1 1 0] 1523 sage: D, P = A.eigenmatrix_right() 1524 sage: D 1525 [3 0 0] 1526 [0 2 0] 1527 [0 0 1] 1528 sage: P 1529 [0 1 1] 1515 1530 [0 1 0] 1516 [0 0 2] 1517 sage: A.eigenspaces() 1518 [ 1519 (2, Vector space of degree 3 and dimension 1 over Rational Field 1520 User basis matrix: 1521 [0 0 1]), 1522 (1, Vector space of degree 3 and dimension 1 over Rational Field 1523 User basis matrix: 1524 [0 1 0]) 1525 ] 1526 \end{verbatim} 1527 1528 A word of caution - if the eigenvalues are not in the base ring of the matrix 1529 space (the eigenvalues below are $\pm \sqrt{3}$) then 1530 the output is incomplete: 1531 [1 0 0] 1532 sage: A*P == P*D 1533 True 1534 \end{verbatim} 1535 1536 A word of caution - if the eigenvalues are not in the fraction field 1537 of the base ring of the matrix space (the eigenvalues below are $\pm 1538 \sqrt{3}$) then the output of \code{eigenspaces_right} and 1539 \code{eigenspaces_left} only lists a single eigenspace for each 1540 irreducible factor of the characteristic polynomial. 1541 1542 Also, currently \sage does not implement multiprecision numerical 1543 eigenvalues/eigenvectors, so calling the eigen functions on a matrix 1544 from \code{CC} or \code{RR} will probably give inaccurate and 1545 nonsensical results (a warning is also printed). Matrices over 1546 \code{CDF} and \code{RDF} should work, though. 1531 1547 1532 1548 \begin{verbatim} 1533 1549 sage: MS = MatrixSpace(QQ, 2, 2) 1534 1550 sage: A = MS([1,-4,1, -1]) 1535 sage: A.eigenspaces ()1551 sage: A.eigenspaces_left() 1536 1552 [ 1537 1553 (a0, Vector space of degree 2 and dimension 1 over Number Field in a0 with defining polynomial x^2 + 3 1538 1554 User basis matrix: … … 1540 1556 ] 1541 1557 sage: MS = MatrixSpace(CC, 2, 2) 1542 1558 sage: A = MS([1,-4,1, -1]) 1543 sage: A.eigenspaces( even_if_inexact=True) # random output1559 sage: A.eigenspaces() # random output 1544 1560 [ 1545 1561 (1.73205080756888*I, [ 1546 1562 ]), -
a/tut/tut.tex
old new 1824 1824 \index{matrix!eigenvectors} 1825 1825 1826 1826 \begin{verbatim} 1827 sage: MS = MatrixSpace(GF(7),2,2) 1828 sage: g = MS([[5, 1], [4, 1]]) 1829 sage: eigvals = [g.eigenspaces()[0][0], g.eigenspaces()[1][0]]; eigvals 1827 sage: g = matrix(GF(7), [[5, 1], [4, 1]]) 1828 sage: g.eigenvalues() 1830 1829 [4, 2] 1831 sage: g.eigenspaces() 1832 [ 1833 (4, Vector space of degree 2 and dimension 1 over Finite Field of size 7 1834 User basis matrix: 1835 [1 5]), 1836 (2, Vector space of degree 2 and dimension 1 over Finite Field of size 7 1837 User basis matrix: 1838 [1 1]) 1839 ] 1830 sage: g.eigenvectors_right() # returns (eigenvalue, [eigenvectors], algebraic multiplicity) 1831 [(4, [ 1832 (1, 6) 1833 ], 1), (2, [ 1834 (1, 4) 1835 ], 1)] 1840 1836 \end{verbatim} 1841 1837 1842 1838 %\subsection{Numerical Linear Algebra}