|
23 | 23 | "\n", |
24 | 24 | "The eigenvalues of $A$ are solutions to the quadratic equation $\\lambda^2 - (a+d)\\lambda + ad-bc = 0$, which can be written explicitly in terms of $a$, $b$, $c$, and $d$ using the quadratic formula. The challenges with larger matrices are that the polynomial is more difficult to construct, and the roots cannot be easily found with a formula.\n", |
25 | 25 | "\n", |
26 | | - "The algorithms we describe in the section are iterative methods. They generate a sequence of vectors $\\{X^{(1)}, X^{(2)}, X^{(3)}, ... \\}$ that approach a true eigenvector of the matrix under consideration. An approximation of the corresponding eigenvalue can then be computed by multiplying the approximate eigenvector by $A$. " |
| 26 | + "The algorithms we describe in this section are iterative methods. They generate a sequence of vectors $\\{X^{(1)}, X^{(2)}, X^{(3)}, ... \\}$ that approach a true eigenvector of the matrix under consideration. An approximation of the corresponding eigenvalue can then be computed by multiplying the approximate eigenvector by $A$. " |
27 | 27 | ] |
28 | 28 | }, |
29 | 29 | { |
|
79 | 79 | "\\end{equation}\n", |
80 | 80 | "$$\n", |
81 | 81 | "\n", |
82 | | - "As a matter of practicality, it is common to scale the vectors in the sequence to unit length as the Power Method is applied. If the vectors in the sequence are not scaled, their magnitudes will grow of $\\lambda_1>1$ or decay if $\\lambda_1<1$. Since all components of the vectors get divided by the same factor when the vector is scaled, this step doesn't change the ultimate behavior of the sequence. The scaled sequence of vectors still approaches the direction of the eigenvector. \n", |
| 82 | + "As a matter of practicality, it is common to scale the vectors in the sequence to unit length as the Power Method is applied. If the vectors in the sequence are not scaled, their magnitudes will grow if $\\lambda_1>1$ or decay if $\\lambda_1<1$. Since all components of the vectors get divided by the same factor when the vector is scaled, this step doesn't change the ultimate behavior of the sequence. The scaled sequence of vectors still approaches the direction of the eigenvector. \n", |
83 | 83 | "\n", |
84 | 84 | "We choose an arbitrary $X^{(0)}$ and calculate $X^{(20)}$ using the following rule.\n", |
85 | 85 | "\n", |
|
92 | 92 | }, |
93 | 93 | { |
94 | 94 | "cell_type": "code", |
95 | | - "execution_count": 2, |
| 95 | + "execution_count": 1, |
96 | 96 | "metadata": {}, |
97 | 97 | "outputs": [ |
98 | 98 | { |
|
176 | 176 | "cell_type": "markdown", |
177 | 177 | "metadata": {}, |
178 | 178 | "source": [ |
179 | | - "Indeed the difference $AX-24X$ small. Note that in this case, we can even do the calculation with integer multiplication. Notice that $X$ has 0 in the first entry and the other entries are equal. If we set these entries to 1, the result is easy to calculate even without the aid of the computer. (*Remember that we can change the magnitude of an eigenvector and it is still an eigenvector.*) \n", |
| 179 | + "Indeed the difference $AX-24X$ is small. Note that in this case, we can even do the calculation with integer multiplication. Notice that $X$ has 0 in the first entry and the other entries are equal. If we set these entries to 1, the result is easy to calculate even without the aid of the computer. (*Remember that we can change the magnitude of an eigenvector and it is still an eigenvector.*) \n", |
180 | 180 | "\n", |
181 | 181 | "$$\n", |
182 | 182 | "\\begin{equation}\n", |
|
191 | 191 | "cell_type": "markdown", |
192 | 192 | "metadata": {}, |
193 | 193 | "source": [ |
194 | | - "In practice, we do not know how many iterations we need to perform in order to get a good approximation of the eigenvector eigenvalue. Instead we should specify a condition upon which we will be satisfied with the approximation and terminate the iteration. For example, since $||AX^{(m)}||\\approx \\lambda_1$ and $AX^{(m)}\\approx \\lambda_1X^{(m)}$ we might require that $AX^{(m)} - ||AX^{(m)}||X^{(m)} < \\epsilon$ for some small number $\\epsilon$ known as a tolerance. This condition ensures that $X^{(m)}$ functions roughly like an eigenvector. It is also best to include in the code a limit on the number of iterations that will be carried out. This ensures that the computation will eventually end, even if a satisfactory result has not yet been achieved." |
| 194 | + "In practice, we do not know how many iterations we need to perform in order to get a good approximation of the eigenvector. Instead we should specify a condition upon which we will be satisfied with the approximation and terminate the iteration. For example, since $||AX^{(m)}||\\approx \\lambda_1$ and $AX^{(m)}\\approx \\lambda_1X^{(m)}$ we might require that $AX^{(m)} - ||AX^{(m)}||X^{(m)} < \\epsilon$ for some small number $\\epsilon$ known as a tolerance. This condition ensures that $X^{(m)}$ functions roughly like an eigenvector. It is also best to include in the code a limit on the number of iterations that will be carried out. This ensures that the computation will eventually end, even if a satisfactory result has not yet been achieved." |
195 | 195 | ] |
196 | 196 | }, |
197 | 197 | { |
198 | 198 | "cell_type": "code", |
199 | | - "execution_count": 5, |
| 199 | + "execution_count": 2, |
200 | 200 | "metadata": {}, |
201 | 201 | "outputs": [ |
202 | 202 | { |
|
251 | 251 | "cell_type": "markdown", |
252 | 252 | "metadata": {}, |
253 | 253 | "source": [ |
254 | | - "A more common condition to require is that $||X^{(m)} - X^{(m-1})|| < \\epsilon$ for a given tolerance $\\epsilon$. This condition mere requires that the vectors in the sequence get close to one another, not that they are actually approximate an eigenvector. " |
| 254 | + "A more common condition to require is that $||X^{(m)} - X^{(m-1})|| < \\epsilon$ for a given tolerance $\\epsilon$. This condition merely requires that the vectors in the sequence get close to one another, not that they are actually approximate an eigenvector. " |
255 | 255 | ] |
256 | 256 | }, |
257 | 257 | { |
|
325 | 325 | "\\end{equation}\n", |
326 | 326 | "$$\n", |
327 | 327 | "\n", |
328 | | - "If $\\lambda$ is an eigenvalue of $A$, then $\\lambda^{-1}$ is an eigenvalue of $A$. Furthermore the eigenvector of $A$ is also an eigenvector of $A^{-1}$. The important point here is that if $\\lambda_n$ is the smallest eigenvalue of $A$, then $\\lambda_n^{-1}$ is the *largest* eigenvector of $A^{-1}$. If we want to approximate the smallest eigenvalue of $A$, we can just apply the Power Method to $A^{-1}$.\n", |
| 328 | + "If $\\lambda$ is an eigenvalue of $A$, then $\\lambda^{-1}$ is an eigenvalue of $A^{-1}$. Furthermore the eigenvector of $A$ is also an eigenvector of $A^{-1}$. The important point here is that if $\\lambda_n$ is the smallest eigenvalue of $A$, then $\\lambda_n^{-1}$ is the *largest* eigenvector of $A^{-1}$. If we want to approximate the smallest eigenvalue of $A$, we can just apply the Power Method to $A^{-1}$.\n", |
329 | 329 | "\n", |
330 | 330 | "We demonstrate the calculation for the following $3\\times 3$ matrix.\n", |
331 | 331 | "\n", |
|
346 | 346 | }, |
347 | 347 | { |
348 | 348 | "cell_type": "code", |
349 | | - "execution_count": 7, |
| 349 | + "execution_count": 4, |
350 | 350 | "metadata": {}, |
351 | 351 | "outputs": [ |
352 | 352 | { |
|
358 | 358 | " [ 6.14168469e-05]\n", |
359 | 359 | " [-8.94437425e-01]] \n", |
360 | 360 | "\n", |
361 | | - "Magnitude of the eigenvalue is A inverse is approximately:\n", |
| 361 | + "Magnitude of the eigenvalue of A inverse is approximately:\n", |
362 | 362 | "0.3333371476391265 \n", |
363 | 363 | "\n", |
364 | | - "Magnitude of the eigenvalue is A is approximately:\n", |
| 364 | + "Magnitude of the eigenvalue of A is approximately:\n", |
365 | 365 | "2.999931351114087 \n", |
366 | 366 | "\n" |
367 | 367 | ] |
|
390 | 390 | " \n", |
391 | 391 | "print(\"Eigenvector is approximately:\")\n", |
392 | 392 | "print(X,'\\n')\n", |
393 | | - "print(\"Magnitude of the eigenvalue is A inverse is approximately:\")\n", |
| 393 | + "print(\"Magnitude of the eigenvalue of A inverse is approximately:\")\n", |
394 | 394 | "print(lag.Magnitude(A_inv@X),'\\n')\n", |
395 | | - "print(\"Magnitude of the eigenvalue is A is approximately:\")\n", |
| 395 | + "print(\"Magnitude of the eigenvalue of A is approximately:\")\n", |
396 | 396 | "print(lag.Magnitude(A@X),'\\n')" |
397 | 397 | ] |
398 | 398 | }, |
|
415 | 415 | }, |
416 | 416 | { |
417 | 417 | "cell_type": "code", |
418 | | - "execution_count": 8, |
| 418 | + "execution_count": 6, |
419 | 419 | "metadata": {}, |
420 | 420 | "outputs": [ |
421 | 421 | { |
|
430 | 430 | "Magnitude of the eigenvalue of A inverse is approximately:\n", |
431 | 431 | "0.3333371476391265 \n", |
432 | 432 | "\n", |
433 | | - "Magnitude of the eigenvalue is A is approximately:\n", |
| 433 | + "Magnitude of the eigenvalue of A is approximately:\n", |
434 | 434 | "2.999931351114087 \n", |
435 | 435 | "\n" |
436 | 436 | ] |
|
460 | 460 | "print(X,'\\n')\n", |
461 | 461 | "print(\"Magnitude of the eigenvalue of A inverse is approximately:\")\n", |
462 | 462 | "print(lag.Magnitude(sla.lu_solve(LU_factorization,X)),'\\n')\n", |
463 | | - "print(\"Magnitude of the eigenvalue is A is approximately:\")\n", |
| 463 | + "print(\"Magnitude of the eigenvalue of A is approximately:\")\n", |
464 | 464 | "print(lag.Magnitude(A@X),'\\n')" |
465 | 465 | ] |
466 | 466 | }, |
467 | 467 | { |
468 | 468 | "cell_type": "markdown", |
469 | 469 | "metadata": {}, |
470 | 470 | "source": [ |
471 | | - "#### Shifts\n", |
| 471 | + "### Shifted inverse power method\n", |
472 | 472 | "\n", |
473 | 473 | "Using a small modification to the Inverse Power Method, we can also approximate eigenvalues that are not the smallest. For this variation of the method, we need to observe that if we \"shift\" the diagonal entries of a matrix by a scalar $\\mu$, all of the eigenvalues of the matrix are also shifted by $\\mu$. Let $A$ be an $n\\times n$ matrix with eigenvalue $\\lambda$ and corresponding eigenvector $V$, so that $AV=\\lambda V$. Then $(A-\\mu I)V = AV - \\mu V = \\lambda V - \\mu V = (\\lambda-\\mu)V$, which means that $V$ is also an eigenvector of the matrix $(A-\\mu I)$ corresponding to the eigenvalue $\\lambda -\\mu$. \n", |
474 | 474 | "\n", |
|
498 | 498 | }, |
499 | 499 | { |
500 | 500 | "cell_type": "code", |
501 | | - "execution_count": 9, |
| 501 | + "execution_count": 7, |
502 | 502 | "metadata": {}, |
503 | 503 | "outputs": [ |
504 | 504 | { |
|
510 | 510 | " [0.88465174]\n", |
511 | 511 | " [0.14744196]] \n", |
512 | 512 | "\n", |
513 | | - "Eigenvalue is A is approximately:\n", |
| 513 | + "Eigenvalue of A is approximately:\n", |
514 | 514 | "6.0\n" |
515 | 515 | ] |
516 | 516 | } |
|
541 | 541 | "\n", |
542 | 542 | "print(\"Eigenvector is approximately:\")\n", |
543 | 543 | "print(X,'\\n')\n", |
544 | | - "print(\"Eigenvalue is A is approximately:\")\n", |
| 544 | + "print(\"Eigenvalue of A is approximately:\")\n", |
545 | 545 | "print(lag.Magnitude(A@X))" |
546 | 546 | ] |
547 | 547 | }, |
|
551 | 551 | "source": [ |
552 | 552 | "### Exercises\n", |
553 | 553 | "\n", |
554 | | - "Let $A$ be the matrix from the Inverse Power Method example.\n", |
| 554 | + "**Exercise 1:** Let $A$ be the matrix from the Inverse Power Method example.\n", |
555 | 555 | "\n", |
556 | 556 | "$$\n", |
557 | 557 | "\\begin{equation}\n", |
558 | 558 | "A = \\left[ \\begin{array}{rrr} 9 & -1 & -3 \\\\ 0 & 6 & 0 \\\\ -6 & 3 & 6 \\end{array}\\right]\n", |
559 | 559 | "\\end{equation}\n", |
560 | 560 | "$$\n", |
561 | 561 | "\n", |
562 | | - "- Use the Power Method to approximate the largest eigenvalue $\\lambda_1$. Verify that the exact value of $\\lambda_1$ is 12." |
| 562 | + "($a$) Use the Power Method to approximate the largest eigenvalue $\\lambda_1$. Verify that the exact value of $\\lambda_1$ is 12." |
563 | 563 | ] |
564 | 564 | }, |
565 | 565 | { |
566 | 566 | "cell_type": "code", |
567 | | - "execution_count": 10, |
| 567 | + "execution_count": 8, |
568 | 568 | "metadata": {}, |
569 | 569 | "outputs": [], |
570 | 570 | "source": [ |
571 | | - "A = np.array([[9,-1,-3],[0,6,0],[-6,3,6]])\n", |
572 | | - "\n", |
573 | 571 | "## Code solution here." |
574 | 572 | ] |
575 | 573 | }, |
576 | 574 | { |
577 | 575 | "cell_type": "markdown", |
578 | 576 | "metadata": {}, |
579 | 577 | "source": [ |
580 | | - "- Apply the Inverse Power Method with a shift of $\\mu = 10$. Explain why the results differ from those in the example." |
| 578 | + "($b$) Apply the Inverse Power Method with a shift of $\\mu = 10$. Explain why the results differ from those in the example." |
581 | 579 | ] |
582 | 580 | }, |
583 | 581 | { |
|
593 | 591 | "cell_type": "markdown", |
594 | 592 | "metadata": {}, |
595 | 593 | "source": [ |
596 | | - "- Apply the Inverse Power Method with a shift 0f $\\mu = 7.5$ and the initial vector given below. Explain why the sequence of vectors approach the eigenvector corresponding to $\\lambda_1$\n", |
| 594 | + "($c$) Apply the Inverse Power Method with a shift of $\\mu = 7.5$ and the initial vector given below. Explain why the sequence of vectors approach the eigenvector corresponding to $\\lambda_1$\n", |
597 | 595 | "\n", |
598 | 596 | "$$\n", |
599 | 597 | "\\begin{equation}\n", |
|
615 | 613 | "cell_type": "markdown", |
616 | 614 | "metadata": {}, |
617 | 615 | "source": [ |
618 | | - "Let $B$ be the following matrix.\n", |
| 616 | + "**Exercise 2:*** Let $B$ be the following matrix.\n", |
619 | 617 | "\n", |
620 | 618 | "$$\n", |
621 | 619 | "\\begin{equation}\n", |
622 | 620 | "B = \\left[ \\begin{array}{rrrr} -2 & -18 & 6 \\\\ -11 & 3 & 11 \\\\ -27 & 15 & 31 \\end{array}\\right]\n", |
623 | 621 | "\\end{equation}\n", |
624 | 622 | "$$\n", |
625 | 623 | "\n", |
626 | | - "- Apply the Power Method and Inverse Power Method with shifts to approximate all eigenvalues of the matrix $B$. (*Note that one of the eigenvalues of this matrix is negative.*)" |
| 624 | + "($a$) Apply the Power Method and Inverse Power Method with shifts to approximate all eigenvalues of the matrix $B$. (*Note that one of the eigenvalues of this matrix is negative.*)" |
627 | 625 | ] |
628 | 626 | }, |
629 | 627 | { |
|
639 | 637 | "cell_type": "markdown", |
640 | 638 | "metadata": {}, |
641 | 639 | "source": [ |
642 | | - "- Check your results using the $\\texttt{eig}$ function in SciPy." |
| 640 | + "($b$) Check your results using the $\\texttt{eig}$ function in SciPy." |
643 | 641 | ] |
644 | 642 | }, |
645 | 643 | { |
|
0 commit comments