Computational Spectroscopy III. Spectroscopic Hamiltonians(a) What is MATLAB?Warnings about MATLABHow will MATLAB help us compute spectra?What we didn’t get from Gaussian or Spartan(b) Matrix OperationsFun with Complex NumbersMore fun with matrices(d) ProgrammingKinds of programs in MATLAB: 1. ScriptsKinds of programs in MATLAB: 2. FunctionsMATLAB Programming TipsFlow control: if … elseif … else … endFlow control: for … end and whileDebugging your programs(e) Eigenvalue problemsFinding eigenvalues with MATLABDiagonalizing the HamiltonianComputational SpectroscopyIII. Spectroscopic Hamiltonians(a) Introduction to MATLAB(b) Matrix operations(c) Programing(d) Diagonalizing Hamiltonian matricesUpdated: March 25, 2008(a) What is MATLAB?MATLAB is the computational environment that we will use to solve spectroscopic Hamiltonians to find the resulting energy levels and wavefunctions.MAT LAB stands for Matrix LaboratoryThe basic object in MATLAB is the matrix.Matrices are constructed, manipulated, matrix problems solved, and the results displayed.Any problem that can be expressed in terms of matrices, that is in terms of linear algebra, can be easily solved in MATLAB.A matrix is an m n array of numbersA vector is a 1 n matrix A scalar is a 1 1 matrix, that is just a number.Complex numbers are no problem in MATLAB.MATLAB calculations can be run in two ways:nType in commands one at a time in the command windownCreate a program, an “M-file”, that contains a series of such commands.MATLAB comands read like ordinary algebraMany high-level matrix operations are available.Each command packs a big punch; you get a lot of work done without much programming.Warnings about MATLABThe hardest part is learning the user interface, and the various kinds of windows that it gives you.You do need to work through the tutorials to learn this.Be careful where you save your stuff.Make a folder in your “My Documents” folder and keep all your MatLab stuff there.Don’t leave any files in the MALAB directory or elsewhere on the computer.The current directory is shown at the top of your main MATLAB window.Your workspace contains all of the data and matrices that you have created.The default name for your workspace is “matlab.mat”, but you can use other names with the “.mat” extension on the file name.Your programs are saved separately as “M-files”, such as “myprog.m”.These are just text files that can be opened and edited with any text editor.You can save your matrices as text files:save ABC.txt ABC -asciiThis saves the matrix ABC in the text file ABC.txt in the current directory. ABC.txt can then be opened with any text editor, with Excel, or other program.Variable and matrix names are case-sensitiveHow will MATLAB help us compute spectra?To compute molecular energy levels, we need to solve the Schroedinger equation H = E . (1)We will be concerned with the nuclear motion, therefore the Hamiltonian is H = T + Eelec(R), (2)where T is the nuclear kinetic energy operator and the effective potential energy is Eelec(R), the electronic energy calculated as a function of the nuclear coordinates R. Eelec(R) is what we could get from Gaussian or from another electronic structure program. To solve the Schroedinger equation (1), we expand the wavefunction as a linear combination of a set of n basis functions, The wavefunction then becomes a vector in the n-dimensional space of the basis functions, the Hamiltonian H becomes an nn matrix, E is a constant, and H = E becomes linear algebra eigenvalue problem, that is solved in MATLAB with the single command “eig”.Hilbert space is the infinite-dimensional vector space of wavefunctions. For practical reasons, we truncate to n dimensions.Most of our work will be in setting up the matrix H.We will also use matrix algebra to make the computer do most of that work.Spectral transition frequencies are obtained by subtracting to get the difference in energy between energy levels connected by the selection rules.€ Ψ = ciφii=1n∑What we didn’t get from Gaussian or SpartanDidn’t solve the quantum mechanics of the nuclear motion.No rotational energy levels or rotational (microwave) spectra.No vibrational energy levels for fundamentals or for overtone and combination bands.Got only classical harmonic frequenciesNo treatment of large-amplitude motion such asTorsion, inversionConformational changeMotion along a reaction coordinateNo coupling of nuclear degrees of freedomVibration-vibration (IVR = intramolecular vibrational redistribution)Rotation-vibration (Coriolis coupling and centrifugal distortion)Quantum chaos Restricted ergodicity (Ergodicity is the core assumption of molecular mechanics calculations)No coupling of electronic and nuclear degrees of freedomRadiationless transitions, dynamics at conical intersections(b) Matrix OperationsLive demonstration. A = [1,2,3;4,5,6;7,8,9]Let A, B be matrices and c and d be constants.The elements of A are Aij, i labels the rows, i=1,m, and j labels the columns, j=1,nscalar multiplication: cA is c*AScalar addition: A+c is A+cMatrix multiplication: C=AB or Cik=jAijBjk C=A*BThe number of columns in A must be equal to the number of rows in B.Indentity matrix: I I = eye(n,n)Always a square matrixMatrix Inversion: I/A = inv(A)= I/A (I must have same dimension as A)A must be square and “non-singular” to have an inverseMatrix division: B/A = B*inv(A)= B/AA matrix raised to a power: A2=AA; A3=AAA; etc. A^3A must be squareExponentiation of a matrix: exp(A) = 1 + A + A2/2! +A3/3! + A4/4! + …= expm(A)Many other functions of matrices are defined. Search “funm” in MATLAB help. € A ≡ A =A11A12A13A21A22A23 ⎡ ⎣ ⎢ ⎤ ⎦ ⎥€ I =1 0 00 1 00 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥Fun with Complex Numbers z =c+d*i with i = sqrt(-1) and c, d reali and j are both predefined in MATLAB as the imaginary unit.Complex conjugation: z* is conj(z) Exponentiation of imaginary number uses Euler’s formula: exp(i*pi) gives -1.000 + 0.000iFunctions and matrix operations work fine with complex numbers (where mathemetically allowed).Complex numbers are user-friendly!!€ exp iz( )= cosz + i sinzMore fun with
View Full Document