# MATLAB Codes

There are numerous MATLAB resources for spectral and pseudospectral methods.
(1) Gautschi, W. Algorithm 726: ORTHPOL—A Package of Routines for Generating Orthogonal Polynomials and Gauss-Type Quadrature Rules, ACM Trans. Math. Software 20, 21-62 (1994). The source codes are here.

(2) MATLAB Differention Suite by Weideman and Reddy ACM Trans. Math. Sci. 26, 465-519 (2000). The source codes are here.

(3) Trefethen, L. N. Spectral Methods in Matlab, SIAM (2000).

(4) Gautschi, W. Orthogonal Polynomials (in MATLAB), J. Comput. Appl. Math 178, 215-234 (2005).

(5) CHEBFUN suite of Matlab codes from Oxford University at chebfun.org

MATLAB codes that accompany Spectral Methods in Chemistry and Physics.

Chapter 3   Chapter 4   Chapter 5   Chapter 6    (Click on a chapter to be redirected.)

Chapter 2 – Click on a file and save, changing the file extension from *.txt to *.m.

Chapter 3: – Click on a file and save, changing the file extension from *.txt to *.m.

Chapter 4: – Click on a file and save, changing the file extension from *.txt to *.m.

 sin_expand_hermite Expansion of sin(x) in Hermite polynomials; Fig. 4.4. The MATLAB code is run three times to produce this figure. Some changes by hand are required between each run to format the graph as noted. plot_kappa Plot_kappa plots the Kappa distribution for 5 kappa values in comparison with the Maxwellian expand_kappa_lag Expansion of the Kappa distribution in Laguerre polynomials demonstrating the nonconvergence; Fig. 4.8 for kappa = 30 with s = 1 and nmax = 25. For kappa = 50, the plotting format has to be changed. wave_packet_cosines Plot the graph for the sum of cosines,  Eq. (4. 105) as shown in Fig. 4.12 wave_packet A model for a quantum mechanical wavepacket as shown in Fig. 4.13 fid A model free induction decay curve and the Fourier transform are shown in Fig.4.14. The frequency spectrum of the signal is recovered with the FFT. fs_step Fourier sine series of a step function shown in Fig. 4.15 as an introduction to Gibbs phenomenon runge_uniform Demonstration of the Runge phenomenon with a uniform interpolation grid for the function, Eq. (4.151)  as shown in Fig. 4.20 (upper graphs). runge_cheb Interpolation of the function, Eq. (4.151) with Chebyshev quadrature points as shown in Fig. 4.20 (lower graph)

Chapter 5: – Click on a file and save, changing the file extension from *.txt to *.m.

 noneq_rx Nonequilibrium effects for an elementary chemical reaction as shown in Fig. 5.4(A) noneq_spectral Spectral convergence of the solution of the Boltzmann equation for an elementary chemical reaction as summarized in Fig. 5.4(C) linbe_gr_eig Eigenvalues of the linearized Boltzmann collision operator, Eq. (5.65). Spectral convergence of the “spectral gap”, λ2. Sonine-Laguerre basis functions are used. linbe_eig Eigenvalues of the linearized Boltzmann collision operator with the pseudospectral method based on the Maxwell polynomial. Maxwell polynomial quadratures are used, Eqs. (5.99) and (5.100). This requires the recurrence coefficients up to N = 200 in ab_maxp2_200 as a *.dat file.(This code could be further vectorized.) linbe_eig_gamma1 Eigenvalues of the linear Boltzmann collision operator, Eqs. (5.108) and (5.110), for mass ratio =1. This requires the recurrence coefficients up to n = 200 in ab_maxp2_200 as a *.dat file. (This code could be further vectorized.) rt_chandra Eigenvalues of the radiative transfer equation, Eq. (5.19), and the extrapolation length. Eq. (5.25)

Chapter 6: – Click on a file and save, changing the file extension from *.txt to *.m.

 Harm_Osc_Fourier Convergence of the eigenvalues for the quantum harmonic oscillator with Fourier basis functions as shown in Fig. 6.14(A). Harm_Osc_Herm1 Eigenvalues of the quantum harmonic oscillator with Hermite basis functions with the representation as in Eq. (6.175) as in Baye and Heenen (1986). The results obtained with this Matlab code shows “ghost” levels as in Table 6.6. Harm_Osc_Herm2 Exact calculation of the eigenvalues of the quantum harmonic oscillator with Hermite basis functions with the representation as in Eq. (6.178). The derivative operator is constructed as in Eq. (3.138) without explicit reference to the harmonic potential. The eigenvalues are exact as are the eigenfunctions  shown in Fig.  (6.15) calculated with this code. SE_electron_potl The convergence of the eigenvalues for the Schroedinger equation with the potential, Eq. (6.180),  based on the  nonclassical polynomials orthogonal with respect to the weight function, Eq. (6.181). The recurrence coefficients for this weight function are in the file ab_se_electron. This Schroedinger equation is isospectral with the Fokker-Planck equation for electron relaxation for a hard sphere cross section, namely Eq. (6.63), with sigma(x) = 1