{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "markdown", "source": [ "#**Computacional Chemistry - PL 3**\n", "\n", "**Unitary (orthogonal) matrices and transformations**\n", "\n", "\\\\\n", "\n", "---\n", "Supporting Bibliography:\n", "\n", "Attila Szabo and Neil S. Ostlund, Modern Quantum Chemistry: Introduction to Advanced Electronic Structure Theory, Dover Publications Inc., New York, 1996, **Capítulo 1, Secção 1.1**\n", "\n", "https://www.geeksforgeeks.org/applications-of-eigenvalues-and-eigenvectors/\n", "---\n", "\n", "\\\\\n", "\n", "**1. Unitrary Transformations**\n", "\n", "We verified that\n", "\n", "$\\boldsymbol{\\Omega} = \\textbf{U}^{\\dagger}\\textbf{OU} =\n", "\\begin{bmatrix}\n", "cos \\theta & sin \\theta \\\\\n", "sin \\theta & -cos \\theta\n", "\\end{bmatrix}\n", "\\begin{bmatrix}\n", "O_{11} & O_{12} \\\\\n", "O_{21} & O_{22} \n", "\\end{bmatrix}\n", "\\begin{bmatrix}\n", "cos \\theta & sin \\theta \\\\\n", "sin \\theta & -cos \\theta\n", "\\end{bmatrix} =\n", "$\n", "\n", "\\\\\n", "$\\begin{bmatrix}\n", "O_{11} cos^{2} \\theta + O_{22} sin^{2} \\theta + O_{12} sin 2\\theta & \\frac{1}{2}(O_{11}-O_{22}) sin 2\\theta - O_{12} cos 2\\theta\\\\\n", "\\frac{1}{2}(O_{11}-O_{22}) sin 2\\theta - O_{12} cos 2\\theta & O_{11} sin^{2} \\theta + O_{22} cos^{2} \\theta - O_{12} sin 2\\theta \n", "\\end{bmatrix}\n", "$\n", "\n", "\\\\\n", "**Problem 1**\n", "\n", "Show that for $\\boldsymbol{\\Omega}$ to be diagonal, the angle $\\theta$ must be given by\n", "\n", "\\\\\n", "$\\theta_{0} = \\frac{1}{2}tan^{-1}\\frac{2O_{12}}{O_{11}-O_{22}} = \\frac{1}{2} arctan\\frac{2O_{12}}{O_{11}-O_{22}}$\n", "\n", "\\\\\n", "**Problem 2**\n", "\n", "Write a Python program that calculates the value of $\\theta_{0}$ given the values ​​of the elements of the matrix **O** ($O_{11}, O_{12}, O_{22}$).\n", "\n", "Note1: Define an arbitrary Hermitean matrix **O** ($2\\times2$)\n", "\n", "Note2: Don't forget to import the numpy library\n", "\n", "Note3: the `np.arctan()` function can be used to calculate $tan^{-1}$ or $arctan$\n", "\n", "Note4: the returned values ​​are in radians. To convert the values ​​to degrees you can use `np.degrees()`" ], "metadata": { "id": "KqADZfYeHzHd" } }, { "cell_type": "code", "source": [ "# Place your code here and make any necessary modifications\n", "#\n", "#\n", "#" ], "metadata": { "id": "YTFyvSUxK8nX" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "**Problem 3**\n", "\n", "What are the eigenvalues ​​of the matrix **O**?\n", "\n", "Recall that $\\boldsymbol{\\Omega} = \\textbf{U}^{\\dagger}\\textbf{OU} =\n", "\\begin{bmatrix}\n", "\\omega_1 & 0 \\\\\n", "0 & \\omega_2\n", "\\end{bmatrix}$\n", "\n", "\\\\\n", "**Problem 4**\n", "\n", "Write a program that calculates the eigenvalues ​​of the matrix **O** defined above" ], "metadata": { "id": "yzRZ8TXbnN1o" } }, { "cell_type": "code", "source": [ "# Place your code here and make any necessary modifications\n", "#\n", "#\n", "#" ], "metadata": { "id": "VjeBeBM2rOIY" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "**Problem 5**\n", "\n", "Note that you can directly use the value of $\\theta_{0}$ and the product $\\boldsymbol{\\Omega} = \\textbf{U}^{\\dagger}\\textbf{OU} =\n", "\\begin{bmatrix}\n", "\\omega_1 & 0 \\\\\n", "0 & \\omega_2\n", "\\end{bmatrix}$ to obtain the eigenvalues. Use the definition of the matrix $\\textbf{U} = \\begin{bmatrix}\n", "cos \\theta & sin \\theta \\\\\n", "sin \\theta & -cos \\theta\n", "\\end{bmatrix}$ to write a program that computes the eigenvalues.\n", "\n", "Note 1: the function `numpy.matrix.H()` returns the transposed complex conjugate matrix. If the matrix is ​​real, we can use `np.transpose()` which returns the transposed matrix. The `.T` attribute can be used in the same way, i.e. `A.T` gives us the transpose of A.\n", "\n", "Note 2: The `np.diag(matrix)` function returns the diagonal elements of a matrix\n", "\n", "Note 3: the `@` operator can be used as a shorthand for `np.matmul` (`np.matmul(A,B)` is equal to `A @ B`)\n", "\n", "Note 4. Trigonometric functions have the general form np.function, e.g. `np.cos()`" ], "metadata": { "id": "H8q_5BA2u9Zn" } }, { "cell_type": "code", "source": [ "# Place your code here and make any necessary modifications\n", "#\n", "#" ], "metadata": { "id": "a7MiK8FBwyK_" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "**Problem 6**\n", "\n", "Show that *tr*(**AB**) = *tr*(**BA**). Use this result to show that the trace of a matrix is ​​invariant under a unitary transformation, i.e., if $\\boldsymbol{\\Omega} = \\textbf{U}^{\\dagger}\\textbf{OU}$, then *tr*$\\boldsymbol{\\Omega}$ = *tr*$\\textbf{O}$\n", "\n", "\\\\\n", "**2. Secular Determinant**\n", "\n", "As we saw in the class, we can also use the Secular Determinant method to solve an eigenvalue equation and, therefore, diagonalize a matrix:\n", "\n", "$\\textbf{O}\\textbf{c} = \\omega \\textbf{c}$ pode reescrever-se como $(\\textbf{O}-\\omega\\textbf{1})\\textbf{c} = 0$\n", "and has solutions\n", "$|\\textbf{O}-\\omega \\textbf{1}| = 0$\n", "\n", "We discovered that for a matrix ($2\\times2$) the eigenvalues ​​are given by:\n", "\n", "\\begin{equation}\n", "\\begin{split}\n", "\\omega_{1} = \\frac{1}{2} [O_{11}+O_{22} -[(O_{11}-O_{22})^{2}+4O_{12}O_{21}]^{\\frac{1}{2}}] \\\\\n", "\\omega_{2} = \\frac{1}{2} [O_{11}+O_{22} + [(O_{11}-O_{22})^{2}+4O_{12}O_{21}]^{\\frac{1}{2}}]\n", "\\end{split}\n", "\\end{equation}\n", "\n", "and therefore, the eigenvectors are:\n", "\n", "\\begin{equation}\n", "\\begin{split}\n", "O_{11}c_{1}^{i} + O_{12}c_{2}^{i} = \\omega_{i} c_{1}^{i} \\\\\n", "O_{21}c_{1}^{i} + O_{22}c_{2}^{i} = \\omega_{i} c_{2}^{i} \\\\\n", "\\end{split}\n", "\\space i = 1,2 ; \\text{ } (c_{1}^{i})^{2}+(c_{2}^{i})^{2} = 1\n", "\\end{equation}\n", "\n", "Remember also that we can write\n", "\n", "\\begin{equation}\n", "\\begin{pmatrix}\n", "O_{11} & O_{12} \\\\\n", "O_{12} & O_{22}\n", "\\end{pmatrix}\n", "\\begin{pmatrix}\n", "c_1^1 \\\\\n", "c_2^1\n", "\\end{pmatrix}\n", "= \\omega_1\n", "\\begin{pmatrix}\n", "c_1^1 \\\\\n", "c_2^1\n", "\\end{pmatrix}\n", "\\quad \\text{e} \\quad\n", "\\begin{pmatrix}\n", "O_{11} & O_{12} \\\\\n", "O_{12} & O_{22}\n", "\\end{pmatrix}\n", "\\begin{pmatrix}\n", "c_1^2 \\\\\n", "c_2^2\n", "\\end{pmatrix}\n", "= \\omega_2\n", "\\begin{pmatrix}\n", "c_1^2 \\\\\n", "c_2^2\n", "\\end{pmatrix}\n", "\\end{equation}\n", "\n", "**Problem 7**\n", "\n", "Calculate the eigenvalues ​​and eigenvectors of the symmetric matrix $\\textbf{O}$ ($2 \\times 2$) using the secular determinant method\n", "\n", "\\begin{equation*}\n", "\\textbf{O} = \\begin{bmatrix}\n", "O_{11} & O_{12} \\\\\n", "O_{21} & O_{22} \n", "\\end{bmatrix}\n", "=\n", "\\begin{bmatrix}\n", "a & b \\\\\n", "b & a \n", "\\end{bmatrix}\n", "\\end{equation*}\n", "\n", "\n", "**Problem 8**\n", "\n", "Consider the following matrices\n", "\n", "\\begin{equation*}\n", "\\boldsymbol{A} = \\begin{bmatrix}\n", "3 & 1 \\\\\n", "1 & 3 \\\\\n", "\\end{bmatrix}\n", "\\text{e}\\space\n", "\\boldsymbol{B} = \\begin{bmatrix}\n", "3 & 1 \\\\\n", "1 & 2 \\\\\n", "\\end{bmatrix}\n", "\\end{equation*}\n", "\n", "Check if they are Hermitian.\n", "\n", "**Problem 9**\n", "\n", "Write the secular determinant for each of the matrices and obtain the eigenvalues.\n", "\n", "**Problem 10**\n", "\n", "Using the eigenvalues ​​from the previous exercise, also obtain the eigenvectors. Verify that they are orthogonal.\n", "\n", "**Exercício 11**\n", "\n", "Write a Python program that calculates eigenvalues ​​of matrices $2\\times2$ and apply the program to matrices **A** and **B**.\n", "\n", "Tips: After declaring the matrix, start by defining the coefficients $a, b, c$ of the quadratic equation $ax²+bx+c$ of the determinants $|\\textbf{A}-ω\\textbf{1}|$ and $|\\textbf{B}-ω\\textbf{1}|$ in terms of the matrix elements.\n", "\n", "Remember that for a matrix $\\textbf{O} = \\begin{bmatrix} O_{11} & O_{12} \\\\ O_{21} & O_{22} \\end{bmatrix}$\n", "\n", "\\\\\n", "$|\\textbf{O}-ω\\textbf{1}| = \\begin{vmatrix}\n", "O_{11} - ω & O_{12}\\\\\n", "O_{21} & O_{22}-ω\n", "\\end{vmatrix} = (O_{11} - ω)(O_{22}-ω) - (O_{21}×O_{12})$\n", "\n", "\\\\\n", "$= O_{11}O_{22}-O_{11}ω-ωO_{22}+ω² -(O_{21}×O_{12})$\n", "\n", "\\\\\n", "$= ω² -(O_{11}+O_{22})ω + (O_{11}O_{22})-(O_{21}×O_{12})$\n", "\n", "\\\\\n", "having $a, b, c$, we can find the roots of the quadratic equation $ax²+bx+c$ using the function `np.roots([a, b, c])`" ], "metadata": { "id": "ofoE6vzEhfPb" } }, { "cell_type": "code", "source": [ "# Place your code here and make any necessary modifications\n", "#\n", "#" ], "metadata": { "id": "RFFeluCGIQBQ" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "*** Assessment Exercise (Home)**\n", "\n", "As expected, there are libraries that perform this task more easily and allow you to efficiently diagonalize/find the eigenvalues ​​of matrices larger than $2\\times2$ .\n", "\n", "The Numpy library has the function `linalg.eig(a)` which, given a square matrix, returns the values ​​and eigenvectors of that matrix.\n", "\n", "Syntax\n", "\n", " ```\n", " # Importing the library\n", " import numpy as np\n", "\n", " # Stores 2 matrices, W and v, with eigenvalues ​​and eigenvectors of the matrix m\n", " w, v = np.linalg.eig(m)\n", " ```\n", "\n", " Write a program that calculates eigenvalues ​​and eigenvectors of square matrices using this function. You can use the previously defined matrices **A** and **B**." ], "metadata": { "id": "5Apo1JElps_i" } }, { "cell_type": "code", "source": [ "# Coloque aqui o seu código e faça as modificações necessárias\n", "#\n", "#" ], "metadata": { "id": "g_S02HjRUhdn" }, "execution_count": null, "outputs": [] } ] }