{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 5 Trig, hyperbolic and inverse functions, waves, polar coordinates, factorials"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"## import all python add-ons etc that will be needed later on\n",
"%matplotlib inline\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from sympy import *\n",
"init_printing() # allows printing of SymPy results in typeset maths format\n",
"plt.rcParams.update({'font.size': 16}) # set font size for plots"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5.1 Trig functions\n",
"\n",
"The common trigonometric functions, sine and cosine, are circular functions because their values repeat as $x$ is increased. Together with the tangent, they are defined as ratios of the sides of a right-angled triangle and are illustrated in Figure 9.\n",
"\n",
"$$\\displaystyle \\begin{align}\\sin(\\theta) &= \\text{opposite / hypotenuse} = \\frac{p}{h} \\\\[10pt] \n",
"\\cos(\\theta) &= \\text{ adjacent / hypotenuse} = \\frac{a}{h}\\\\[10pt] \n",
"\\tan(\\theta) &= \\text{opposite / adjacent} = \\frac{p}{a}\\end{align}$$\n",
"\n",
"and\n",
"\n",
"$$\\displaystyle \\tan(\\theta) = \\frac{\\sin(\\theta)}{\\cos(\\theta)}$$\n",
"\n",
"The cosine is the projection of the hypotenuse onto the x-axis, and the sine the projection onto the y- or vertical axis. The tangent is the gradient of the hypotenuse.\n",
"\n",
"There are very many relationships between the trig functions; some of the most commonly met are, for angles $x$ and $y$ are shown below\n",
"\n",
"$$\\displaystyle \\textbf{Table of trig relationships}$$\n",
"$$\\displaystyle \\begin{array}{lll}\\\\\n",
"\\hline\n",
"\\sin(-x) =-\\sin(x) & \\cos(-x)=\\cos(x)\\\\[5pt]\n",
"\\cos^2(x)+\\sin^2(x)=1 & \\cos^2(x)-\\sin^2(x)=2\\cos^2(x)-1 = \\cos(2x) &\\\\[5pt]\n",
"\\cos^2(x)=(1+\\cos(2x))/2 & \\sin^2(x)=(1-\\cos(2x))/2 &\\\\[5pt]\n",
"\\sin(2x)=2\\sin(x)\\cos(x)& \\sin(x)+\\cos(x)=\\sqrt{2}\\sin(x + \\pi /4)\\\\[5pt]\n",
"\\hline\n",
"\\sin(x\\pm y)=\\cos(x)\\sin(y)\\pm\\sin(x)\\cos(y) & \\cos(x\\pm y)=\\cos(x)\\cos(y)\\mp\\sin(x)\\sin(y) \\\\[5pt] \\displaystyle \\tan(x\\pm y) =\\frac{\\tan(x)\\pm\\tan(y)}{1\\mp\\tan(x)\\tan(y)}\\\\\n",
"\\hline\n",
"\\displaystyle \\cos(x)+\\cos(y)=2\\cos\\left(\\frac{x+y}{2}\\right)\\cos\\left(\\frac{x-y}{2}\\right)\\\\\n",
"\\displaystyle\\cos(x)-\\cos(y)=-2\\sin\\left(\\frac{x+y}{2}\\right)\\sin\\left(\\frac{x-y}{2}\\right)\\\\\n",
"\\displaystyle\\sin(x)\\pm\\sin(y)=2\\sin\\left(\\frac{x\\pm y}{2}\\right)\\cos\\left(\\frac{x \\mp y}{2}\\right)\\\\\n",
"\\hline\\end{array}$$\n",
"\n",
"The sine, cosine, and tangent functions can also be described as series expansions, see Chapter 5, and as complex exponential functions. The equations are given here but described in detail in Chapter 2, which describes complex numbers.\n",
"\n",
"$$\\displaystyle\\sin(x)=\\frac{e^{ix}-e^{-ix} }{2i}, \\qquad \\cos(x)=\\frac{e^{ix}+e^{-ix}}{2}$$\n",
"\n",
"The word tangent derives from the Latin _tangere_, which means to touch, and this is also the usage when the tangent is used to define the gradient of a curve at a given point, Figure 10. If the curve is a circle, the tangent is perpendicular to the radius.\n",
"\n",
"Although hand-held calculators usually use degrees to calculate trigonometric functions, this disguises the fact that these functions require the angle to be in _radians_. A radian is the angle subtended at the centre of a circle by travelling a distance around the circumference that is equal to its radius, thus a complete rotation of $360^\\text{o} \\equiv 2\\pi$ radians and 1 radian is approximately $57.5^{\\text{o}}$. Radians are not always included as units; the exception is in the study of NMR where the magnetogyric ratio $\\gamma$, which is the constant that relates the magnetic dipole to the magnetic field, is always quoted in $\\mathrm{rad\\, T^{-1} s^{-1}}$, the T here representing the unit Tesla. In spectroscopy generally, frequencies are usually quoted either as $\\mathrm{s^{-1}}$, with the symbol $\\upsilon$, or as angular frequencies, $\\omega$ in rad s$^{-1}$. These are related as $2\\pi \\upsilon = \\omega$.\n",
"\n",
"![Drawing](chapter1-fig9.png)\n",
"\n",
"Figure 9 Trigonometric relationships in a right-angled triangle and relationships to the x- and y-axes.\n",
" \n",
"![Drawing](chapter1-fig10.png)\n",
"\n",
"Figure 10 The tangent touches the curve at a point and defines the gradient at that point.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5.2 Waves\n",
"\n",
"In electromagnetic radiation, such as X-rays or radio waves and, more familiarly, visible light, the periodic displacement of the electric and magnetic fields is described by a sine or cosine function. Similarly, sine and cosine describe the periodic displacement of molecules as a sound wave travels through a gas, liquid, or solid, and describe a molecule's internal vibrational normal modes. Any motion described by a single sine or cosine is called simple harmonic motion (SHM), for example, the motion of a pendulum. A spring is often called a harmonic oscillator and this term is also used to describe molecular vibrations. Mathematically, waves form the basis of the Fourier transforms and Fourier series method described in Chapter 9.\n",
"\n",
"A sine wave is defined by its wavelength, amplitude, and phase. The amplitude is its maximum vertical displacement from zero. The wavelength is one full or two half periods and is the distance from one node to the next but one. A node is any of the points where the wave has zero amplitude.\n",
"\n",
"In a _longitudinal wave_, such as a sound wave, the gas molecules are made to move about their equilibrium position in simple harmonic motion by the disturbance generating the sound. This simple harmonic motion occurs along the direction that the wave travels. The wave moves through the gas because molecules interact with one another causing regions of increased pressure and rarefaction. Even though each molecule only moves about its equilibrium position as it does so, it influences its neighbour and the wave moves. A Mexican Wave at a football or cricket match is an example of how the wave moves but each particle (a person in this case) does not move from equilibrium. The speed of the wave is governed by how well one molecule (person) interacts with its neighbour and therefore depends on the properties of the medium. In a gas, the speed is $v = \\sqrt{\\gamma RT/M}$ where $\\gamma$ is the ratio of heat capacities at constant pressure and volume which is $1+2/5$ for an ideal diatomic gas and $5/3$ for an ideal atomic gas such as argon. A helical 'slinky' spring toy can be seen to exhibit longitudinal waves.\n",
"\n",
"In _transverse waves_, such as a water wave, electromagnetic radiation, or a taut wire in a guitar or violin, the displacement of the particles about equilibrium is at right angles to the direction in which the wave is travelling. In a taut wire the wave's velocity is $v = \\sqrt{T/\\mu}$ where $T$ is the tension ( the force in Newtons ) and $\\mu$ the mass per unit length. The units are $\\displaystyle \\left(\\frac{N}{(kg/m)}\\right)^{1/2}\\equiv \\left(\\frac{kg m/s^2}{(kg/m)}\\right)^{1/2} = \\frac{m}{s}$.\n",
"\n",
"![Drawing](chapter1-fig11.png)\n",
"\n",
"Figure 11 Left: The wave on the left is $y = \\sin(2\\pi x/\\lambda)$. The particle (circle) remains at a fixed $x$ but is displaced and follows SHM motion as the wave passes. After one period, it is at the same displacement. Right: The particle's motion is shown with time; the wave is $y = \\sin(2\\pi \\upsilon t)$. After one or any whole number of periods the particle (circle) is again at the same displacement $y$.\n",
"_____\n",
"\n",
"If a wave is represented as amplitude vs. distance $x$, then a particle remains at one $x$ value and performs simple harmonic or sinusoidal motion at that position as time progresses. Its displacement amplitude is\n",
"\n",
"$$\\displaystyle y = A\\sin(kx+\\varphi) $$\n",
"\n",
"The term $k$ is sometimes called the _wavevector_ and is $k = 2\\pi/\\lambda$ where $\\lambda$ is the wavelength. The phase is $\\varphi$ (radians) which might be zero, is a constant displacement of the wave. At zero $x$ the amplitude is $A\\sin(\\varphi)$. Sine and cosine always have a fixed phase difference between them of $\\pi /2$ or $90^\\text{o}$, thus a sine wave is changed into a cosine, and vice versa by a $\\pi/2$ phase change.\n",
"\n",
"If the plot is one of amplitude vs time then the wave represents how the particle moves in time at a given position. The wavelength is now the period $T$ of the motion and $T = 1/\\upsilon$ where $\\upsilon$ is the frequency in $\\mathrm{s^{-1}}$. The angular frequency is $\\omega = 2\\pi\\upsilon$, in radian $\\mathrm{s^{-1}}$, hence the following equations are equivalent\n",
"\n",
"$$\\displaystyle y = A\\sin(\\omega t+\\varphi)= A\\sin(2\\pi\\upsilon t+\\varphi) $$ \n",
"\n",
"The velocity of the wave $v$ is the product of frequency and wavelength; $v = \\upsilon\\lambda= \\omega/k$. The general equation for a travelling wave, either transverse or longitudinal, is\n",
"\n",
"$$\\displaystyle y = A\\sin(\\omega t - kx +\\varphi) \\tag{16}$$ \n",
"\n",
"In this equation the sign $-kx$ means that the wave is travelling to the right, which is positive $x$. If the term were written $+kx$, then the wave would be travelling to the left. Depending upon whether $x$ or $t$ is plotted the similar but different plots in Figure 11 are produced. On the left the displacement $x$ is plotted and therefore as time progresses the particle moves up and down at fixed $x$. On the right the displacement vs time at a fixed $x$ is plotted.\n",
"\n",
"The phase $\\varphi$ (figure 12) displaces the wave but does not change its frequency or wavelength. The dashed curve, Figure 12 has $\\varphi = +2/3$ radians compared the solid curve where the phase is zero. Note that a positive phase displaces the curve to the left compared to zero phase.\n",
"\n",
"![Drawing](chapter1-fig12.png)\n",
"\n",
"Figure 12 Comparison of $\\sin(2\\pi\\upsilon t + 2/3)$ with $\\upsilon = 1$ (dashed line) compared to the sine wave with zero phase.\n",
"____\n",
"\n",
"When two waves are added they can reinforce or destroy one another depending on their phase. Clearly, when they are in phase, the phase being zero or integer multiples of $2\\pi$, the waves add and a double-sized wave is produced. When $180^\\text{o}$ or integer multiples of $\\pi$ out of phase destructive interference occurs.\n",
"\n",
"If the waves are of different frequency then they become out of step with one another, as shown in Figure 13. However, the two waves will periodically have places where both waves have zero amplitude. The effect is called _beating_ and in a sound wave this is heard as a repeating hum, hence 'beats', when the second sound wave is turned on. The beat frequency is the difference in frequency of the two individual waves and is twice the lowest frequency of the combined wave. The combined wave has frequencies that are half the sum and half difference of the two fundamental waves. Figure 13 shows this effect on waves with $\\upsilon$ = 5 and 5.5 Hz. The beating is clear when the waves are added together. The dashed line shows the sine wave at the difference frequency, 0.5 Hz. The sum wave is \n",
"\n",
"$$\\displaystyle\\cos\\left(2\\pi\\upsilon_1 t\\right)+\\cos\\left(2\\pi\\upsilon_2 t\\right)=2\\cos\\left(2\\pi\\frac{\\upsilon_1-\\upsilon_2}{2}\\right)\\cos\\left(2\\pi\\frac{\\upsilon_1+\\upsilon_2}{2}\\right)$$\n",
"\n",
"![Drawing](chapter1-fig13.png)\n",
"\n",
"Figure 13 Left: the two travelling waves of frequency $\\upsilon = 5$ and $5.5$ quickly become out of step with one another. Right: the sum of the waves shows beating with a beat frequency of 0.5 Hz (red dashed line) and a higher frequency at the sum of the frequencies. (Note that different abscissa are used).\n",
"____\n",
"\n",
"## 5.3 Phase and group velocity\n",
"\n",
"A wave is defined with an angular frequency $\\omega = 2\\pi\\nu$ and wavevector \n",
"\n",
"$$\\displaystyle k = 2\\pi/\\lambda$$\n",
"\n",
"and has the general form of equation (16). The _phase velocity_ is what we would colloquially describe as the velocity of a wave and is \n",
"\n",
"$$\\displaystyle v = \\omega/k= \\nu\\lambda$$\n",
"\n",
"with units distance/time. \n",
"\n",
"If the medium is _dispersive_, as is air or glass to visible light, then $\\omega/k$ is not constant. Dispersion means that the medium through which the wave is passing affects the wave so that the phase velocity of the wave depends on the frequency; thus, red light is transmitted through the same piece of glass in less time than blue light. The refractive index at short (blue) wavelengths is larger than at longer wavelengths. The speed of light in a medium of refractive index $n_\\lambda$ at wavelength $\\lambda$ is $c_n = c/n_\\lambda$ where $c$ is the speed of light in vacuum defined as $c=2.99792458\\cdot 10^8 \\,\\mathrm{m\\,s^{-1}}$.\n",
"\n",
"The _group velocity_ $v_g$ is a second measure of the speed of a wave-like disturbance. It applies only when a wave is composed of many individual waves of different frequencies and is defined as $\\Delta \\omega /\\Delta k$. The superposition of these waves does not remain constant in time and therefore the profile of the disturbance changes with time, although each individual wave moves with its phase velocity. The group velocity is also the speed at which energy is transmitted and is the speed at which the maximum of the combined wave moves.\n",
"\n",
"If the frequencies in the group of waves are similar, then the change $\\Delta \\omega /\\Delta k \\to d\\omega /dk = v_g$ can be made. As the phase velocity is $v = \\omega/k$ then\n",
"\n",
"$$\\displaystyle v_g =\\frac{d\\omega}{dk} = v + k\\frac{dv}{dk}=\\nu-\\lambda\\frac{dv}{d\\lambda}$$\n",
"\n",
"If the gradient $\\displaystyle \\frac{dv}{d\\lambda} \\gt 0$ then the medium exhibits what is called normal dispersion (e.g.,visible light in glass); when $\\displaystyle \\frac{dv}{d\\lambda} \\lt 0$ it is called anomalous dispersion. This is normally the case for electromagnetic waves in an electrical conductor and in the far infrared part of the spectrum. In quantum mechanics, it is sometimes useful to calculate the phase velocity of wave/particle as $v = E/p$ because the kinetic energy is $E = p^2/2m$ where $p$ is momentum. Similarly, \n",
"\n",
"$$\\displaystyle v_g =\\frac{d\\omega}{dk}=\\frac{dE}{dp}$$\n",
"\n",
"is the group velocity.\n",
"\n",
"## 5.4 Standing waves\n",
"\n",
"The fundamental and overtone waves formed in a taut wire when it is struck, such as on a guitar or violin, or those in the quantum mechanical particle in a box, are standing waves. They rise and fall in time with their nodes remaining at the same place. Thus, sometimes they are completely zero everywhere, and at other times they are maximal. When two similar waves travelling in opposite directions are added, a standing wave is formed. This can be shown if the waves are written as $y_1 = \\sin(k(x - v t))$, which means that the wave moves to the right along the x-axis with velocity $v$, and the wave $y_2 = A\\sin(k(x + v t))$ moves to the left. With some manipulation the sum of these waves is $y = 2\\cos(kvt)\\sin(kx)$, which is a sine wave which remains fixed along $x$ but whose amplitude rises and falls in time with frequency $\\omega = kv$. \n",
"\n",
"In practice, if you strike the strings of a violin or piano the motion produced is complex because many fundamental frequencies (called normal modes) are simultaneously excited when the instrument is played. Some calculations that illustrate this are presented in Chapter 7. In musical instruments there are also many overtones produced and it is these that give instruments their characteristic sounds.\n",
"\n",
"![Drawing](chapter1-fig13a.png)\n",
"\n",
"Figure 13a. A standing wave. The amplitude changes in the way indicated by the arrows, then repeats in the opposite sense and so on _ad infinitum_.\n",
"_____\n",
"\n",
"## 5.5 Superposition of waves of the same frequency\n",
"\n",
"A defining characteristic of waves is that they can form superpositions, which is to say that when added or subtracted a new waveform is produced. When the waves are of the same frequency (or wavelength) this leads to interference and diffraction phenomena. When waves of different frequency are added beats are produced as described above. In quantum mechanics wavepackets are formed as superpositions of wavefunctions and are described in Chapter 5, (Summation and Series). \n",
"\n",
"### **(i) Example from x-ray diffraction**\n",
"\n",
"In x-ray diffraction the x-rays are scattered by the atoms that are present in regular and repeated positions in a crystal. The smallest set of repeated positions is called the unit cell. The Bragg equation $n\\lambda = 2d\\sin(\\theta) $ defines the angle $\\theta$ that the x-rays are diffracted off planes with a separation $d$. Only some angles cause diffraction because $n$ is an integer and the values of $d$ are determined by the limited number spacing between atoms. As the incident and diffracted angle are equal at $\\theta$ the diffracted rays can be considered to be reflected off the lattice planes. Only the diffracted (reflected) waves that interfere constructively with one another to produce light spots on the detector. Diffraction with crystals is described in more detail in Chapter 9, Fourier Transforms.\n",
"\n",
"A general wave of frequency $\\omega$ has the form \n",
"\n",
"$$\\displaystyle \\psi=a\\cos(\\omega t +\\varphi)=a\\cos(\\omega t)\\cos(\\varphi)-a\\sin(\\omega t)\\sin(\\varphi)$$\n",
"\n",
"where $\\varphi$ is the phase and the expansion formula of $\\cos(x+y)$ was used, see section 5.1. As the phase varies from $0\\to \\pi$ the amplitude of the sine and cosine changes from $1$ to $-1$. The phase can only be in the range $0\\to 2\\pi$ any other values simply return values in this range because of the periodic nature of sines and cosines. In x-ray diffraction the phase is proportional to the perpendicular distance $x_i$ from the lattice plane to each atom and $\\varphi_i=2\\pi x_i/d$\n",
"\n",
"The sum of waves from the $N$ atoms in the unit cell is \n",
"\n",
"$$\\displaystyle \\psi = \\sum_{i=1}^N a_i\\cos(\\omega t)\\cos(\\varphi_i)-\\sum_{i=1}^Na_i\\sin(\\omega t)\\sin(\\varphi_i) $$\n",
"\n",
"The number $N$ will be small for most molecules such as benzene, typically one or two times the number of atoms in the molecule, but is thousands for large proteins. As the x-ray frequency is constant, and does not depend on $N$ its terms can be removed from the summation,\n",
"\n",
"$$\\displaystyle \\psi = \\cos(\\omega t)\\sum_{i=1}^N a_i\\cos(\\varphi_i)-\\sin(\\omega t)\\sum_{i=1}^Na_i\\sin(\\varphi_i) $$\n",
"\n",
"The sum of several cosines is also a cosine, and similarly for sines, thus it follows that if $a_s$ and $\\varphi_s$ are the resultant amplitude and phase respectively, that we can write\n",
"\n",
"$$\\displaystyle a_s\\cos(\\varphi_s)=\\sum_{i=1}^N a_i\\cos(\\varphi_i) \\\\ a_s\\sin(\\varphi_s)=\\sum_{i=1}^N a_i\\sin(\\varphi_i)$$\n",
"\n",
"which means that the amplitude at any point is the sum of that for each wave. The total wave is,\n",
"\n",
"$$\\displaystyle \\psi = a_s\\cos(\\omega t)\\cos(\\varphi_s) - a_s\\sin(\\omega t)\\sin(\\varphi_s) $$\n",
"\n",
"In detecting infra-red, visible light or even x-rays the intensity $I$ is always measured, because of the nature of the interaction of electromagnetic radiation with the atoms and molecules in the detector. The $\\omega t$ terms cannot be measured as the frequency is far too high, and is averaged in the measuring process and can therefore be absorbed into the amplitude and so ignored. The intensity is the square of the wave's amplitude $I=a_s^2$ and adding the squares of $a_s\\cos(\\varphi_s)$ and $a_s\\sin(\\varphi_s)$ and using $\\cos^2(\\varphi_s)+\\sin^2(\\varphi_s)=1$ we find that $a^2$ is produced as\n",
"\n",
"$$\\displaystyle I\\equiv a_s^2 = \\left(\\sum_{i=1}^N a_i\\cos(\\varphi_i)\\right)^2+ \\left(\\sum_{i=1}^N a_i\\sin(\\varphi_i)\\right)^2 \\tag{16a}$$\n",
"\n",
"with overall phase $\\varphi_s$ given by\n",
"\n",
"$$\\displaystyle \\tan(\\varphi_s) =\\frac{\\sum_{i=1}^N a_i\\sin(\\varphi_i)}{\\sum_{i=1}^N a_i\\cos(\\varphi_i)}$$\n",
"\n",
"A more general derivation of the superposition is given in chapter 9, Fourier Series and Transforms.\n",
"\n",
"To recap, the intensity $I$ is that due to all atoms in the unit cell in proportion to their phase $\\varphi_i$ and is unique at each possible scattering angle $\\theta$, thus in x-ray diffraction from crystals the positional information is contained in the intensity of the measured spots on the detector not their position.\n",
"\n",
"### **(ii) Example with two waves**\n",
"\n",
"Suppose that there is a grating with small apertures separated by $d$ and a second set also with separation $d$ but displaced by $\\alpha d$ as shown in the figure below. We can consider these apertures as point emitters producing equal amplitude waves of the same frequency and in phase. They could be, for example, atoms scattering x-rays. At a certain angle the waves with spacing $d$ have phase difference $2\\pi n$, i.e. these waves combine constructively to give a line at order $n$. The other source has a phase difference relative to the first of $\\varphi = 2\\pi\\alpha n$. On the detector the total wave intensity is observed at orders $n=0,\\pm 1,\\pm 2\\cdots$ and the phases are $\\varphi_0 = 0, \\varphi_1=2\\pi n \\alpha$ and from eqn. 16a and assuming the amplitudes are unity for simplicity, the intensity for a wave from each sets is, \n",
"\n",
"$$\\displaystyle \\begin{align} I &= \\left(\\cos(0)+\\cos(\\varphi_1)\\right)^2+ \\left( \\sin(0)+\\sin(\\varphi_1)\\right)^2\\\\&= (1+\\cos(\\varphi_1))^2+\\sin^2(\\varphi_1)\\\\\n",
"&=2\\big(1+\\cos(\\varphi_1)\\big)\\end{align}$$\n",
"\n",
"If $\\cos(\\varphi_1)+1=0$ or $\\cos(2\\pi n\\alpha)=-1$ then a bright line will be missing at order $n$ in the diffraction. This will happen when the cosine has a value of $-1$ or $2\\pi n\\alpha = m\\pi$, i.e. at all odd integer values $m=\\pm 1,\\pm 3\\cdots $ of $\\pi$.\n",
"\n",
"![Drawing](chapter1-fig13b.png)\n",
"\n",
"Figure 13b. Two slits (blue dots) each separated by distance $d$ but one pair is displaced by $\\alpha d$. This displacement causes a phase shift $\\varphi=2\\pi n d$ with respect to the other pair for diffracted order $n$.\n",
"___________\n",
"\n",
"## 5.6 Hyperbolic functions\n",
"\n",
"The hyperbolic functions are closely related to the circular functions, sine, cosine, etc. of trigonometry. The equation of a (unit) circle is $x^2 + y^2 = 1$ and in parametric form $\\cos(\\theta) = x,\\; \\sin(\\theta) = y$ and any point has coordinates $(\\cos(\\theta), \\sin(\\theta))$ }. The equation for a hyperbola is $x^2 - y^2 = 1$ or, in parametric form, $\\cosh(t) = x,\\; \\sinh(t) = y$, but $t$ is not a measure of angle. The two curves produced are shown in figure 14, and one point plotted on each, at a value of $\\theta$ and $t =2\\pi/3$. The hyperbolic functions are often pronounced, 'shine', 'cosh' and 'than', with emphasis on the 'th'. \n",
"\n",
"The shape of a freely hanging cable supported at its ends only, follows the equation $y = \\cosh(x)$, and is called a *catenary*. The arch in St Louis in the United States follows closely that of an inverted cosh. The equations of the hyperbolic functions are similar to those of normal trig functions, but not identical, for example;\n",
"\n",
"$$\\displaystyle \\tanh(x)=\\frac{\\sinh(x)}{\\cosh(x)},\\qquad \\cosh^2(x)-\\sinh^2(x)=1, \\qquad \\cosh^2(x)+\\sinh^2(x)=\\cosh(2x)$$\n",
"\n",
"These identities can be checked using SymPy, for example"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAFoAAAAUCAYAAAAN+ioeAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAABJ0AAASdAHeZh94AAAFfElEQVR4nO3Yf+zWVRUH8BdgLqqtEnI2WMHWshyloyTbxMGSnNkM7cdWDVSSnM7QlYY02fGokZZJP9UpJupyyviOWETQWm5pzgwGLSKzmho2SIqwaZkh9Me9z7fP9+HzfR7xa9qosz07n+fcc8+59/0599xzPqP27dvn//Sfp9Ev9QL+V+iQl3oBTcrMSXgYt0bEmSO0dStOxuSIeGrkq3tOPt+BDZgfEcuaY/9VQL9QlJnHYg4uaoKcmeNwGk7B2zABz+AXuAW3RMTe5+s3IjZm5ndwRWbeGRFPdsYO1tTxefwV13fJP4yb8C78FF/BAKZgGVZk5qgR+v4CjsCCpvCgAzoz34wTsSIi/t41/BBOxcSI+HhELIqIeXgLtuGDOH0k/iPiATyIczJzEN/9UkdmTsNncDzGY5dytJZFxIqG3kdwPo7Gofgt7sC1EfGPFrun4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FfZn4Rn8WWzFyJp5STMAX34ktdjlfhycy8H48ob3t6tbsRP+y12QOkAaXDO0lpogYpM8/A5UqdfQ8WZGb3/EciYnnVPwZrlDQ4KyK2Q0SszMwN+EBmTo+Ie7psvLf6WN0RDLlYIuImpSNco6SGi5WWdSe+2dBbiI8qL2KucsGNVt70rJab+BKltpyqND5n4WVYqLy8/cq+EdCAkhvntoxNrnwMLkS0/M5kMA2uwz4lkn/XZWtR5UOCqlZbs7GmVipg1MH44b82T0swNSI29dN/gX1/Cl9Tmr57O/KD7qNSpaVKc3P5i+k0M8cqkT7QBJmDFOiIeFppPjbUtvzFokm4UfkEMYT+Bb2l8xgNq2TrAAAAAElFTkSuQmCC\n",
"text/latex": [
"$\\displaystyle \\cosh{\\left(2 x \\right)}$"
],
"text/plain": [
"cosh(2⋅x)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x = symbols('x')\n",
"simplify( cosh(x)**2 + sinh(x)**2 )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"produces the result $\\cosh(2x)$. \n",
"\n",
"The circular functions sine, cosine, and tangent can be represented as real functions involving complex exponentials, see Chapter 2. The hyperbolic functions $\\sinh(x),\\; \\cosh(x),$ and $\\tanh(x)$ are also real functions and can also be represented as real exponentials. The hyperbolic functions are\n",
"\n",
"$$\\displaystyle \\sinh(x) = \\frac{e^x - e^{-x}}{2},\\qquad \\cosh(x) = \\frac{e^x + e^{-x}}{2},\\qquad \\tanh(x) = \\frac{e^x - e^{-x}}{e^x + e^{-x}}$$\n",
"\n",
"Some values are\n",
"\n",
"$$\\displaystyle\\begin{array}{lll}\n",
"\\sinh(0)=0 & \\sinh(\\infty)=\\infty \\\\\n",
"\\cosh(0)=1 & \\cosh(\\infty)=\\infty \\\\\n",
"\\tanh(0)=0 & \\tanh(\\pm\\infty)=\\pm 1\\\\\n",
"\\end{array}$$\n",
"\n",
"The functions are plotted in figure 15 and compared to the normal trig functions.\n",
"\n",
"![Drawing](chapter1-fig14.png)\n",
"\n",
"Figure 14. Circle and hyperbola. The point is at $\\theta$ or $t= \\pi/4$.\n",
"\n",
"![Drawing](chapter1-fig15.png)\n",
"\n",
"Figure 15. Some of the hyperbolic and normal trigonometric functions. Notice how $\\tan(x)$ goes to $\\pm\\infty$ in multiples of $x = \\pm\\pi/2$.\n",
"\n",
"________"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6 Inverse functions\n",
"\n",
"The log and exponential functions are inverses of one another, and similarly $x^n$ and $x^{1/n}$ because when one is made a function of the other, the result is $x;\\; \\ln(e^x) = x$ and $(x^{1/n})^n = x$. If the function is written as $f(x)$ then the inverse is $f^{-1}(x)$, therefore\n",
"\n",
"$$\\displaystyle f^{-1}[f(x)] = x$$\n",
"\n",
"However, not all functions have an inverse. When plotted the observation is that one function is the reflection of the other through a straight line of gradient $\\pm 1 $, such as shown in figure 8 for the positive exponential and log. More formally, the function and its inverse must have a one-to-one relationship. If an inverse exists when the function $f (x)$ is solved for $x$, then $x$ and $y$ exchanged and the result substituted into the original equation, $x$ results. For example, if $f(x) \\equiv y = (x + 2)/3$ then $x = 3y - 2$, the inverse function is found by swapping $y$ for $x$, giving $f^{-1}(x) = 3x - 2$, and then substituting back $f^{-1}[f(x)] = 3(x + 2)/3 - 2 = x$.\n",
"\n",
"The function $y = \\sin(x)$ has $y = \\sin^{-1}(x)$ as its inverse function, which can be written as $\\sin(y) = x$, which is a sine wave moving up the y-axis, as shown in figure 16. Similarly there are inverse functions $\\cos^{-1}(x)$ and $\\tan^{-1}(x)$. Notice that the computer notation is different to the mathematical one; for example, $\\sin^{-1}(x) \\equiv \\arcsin(x)$, the prefix 'arc' being added to these inverse functions, but this notation is not universal and in some languages asin may be used instead of arcsin etc.\n",
"\n",
"The inverse trig functions are multi-valued; the principal range for $\\sin^{-1}(x)$ and $\\cos^{-1}(x)$ is $x = \\pm 1$ and the function's principal values lie between $y = \\pm \\pi/2$. The inverse function $\\tan^{-1}(x)$ is also multi-valued and ranges from $x = \\pm \\infty$ and has principal values between $y = \\pm\\pi/4$.\n",
"\n",
"The equations defining inverse trig and hyperbolic functions are shown below, and some of which were obtained using Sympy for example,"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAKgAAAAfCAYAAABzhIZ5AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAABJ0AAASdAHeZh94AAAHaklEQVR4nO2bf6yWZRnHPweTVpIUrjw0ZqSFOfqBuEwKFlbKgjYasfyxEEq3wpxpQnIQ9j3fFDbxRweLWm7VUdM0bbF5rBBNXWVYGVKYyjBYUkjl4Bi2RPT0x30/+PCc9z3Pe16e9zwP7ny3d/fe+77u+/4+z3W994/rul76+vqo+qezs3NU2RyGPy3R61F5Mq+j4rB9CnAKcGPZXIqA7SOBfWXzqApsL5d0Vb32Shuo7bcCVwKzy+ZSIM4ALpT0nbKJVAG2L7d9lqQ7arWPGGpCg8S3gBWSXiqbSIGYBdxTNokK4TrgUtvH1mqsrIHangacJOk3ZXMpGMdJ+lvZJKoCSfuBO4GVtdora6DAMuAHZZMoErYnAo+XzaOC+CFwju13ZBsqaaC2jwfOBH5aNpeCMby914CkXcDvgfOzbZU0UOAsYLek7WUTKRhTgIfLJlFR/BE4J1tZ1Vv8x4CNZZMoErZHA3slvVzAWB3AHOBE4EVgA9AhafOhjl0iNgKX2B4naUdSWdUV9FTgL2WTKBgzgHsLGms68G3gw4Qf837gPttjChq/DCT6/lC6snIrqO23AUcDe0qmUjQ+CXytiIEkzUh/tz0P6AU+AtxdxBwlYE8sT0hXHjBQ2+OBbcBNkhYMFasaGBvL50vkUChstwFjJP2rRVO8ibAb7m7R+HVhey7wUWAS8IHI5VZJnxvkUIm+x6YrK7eCAqNi2Vsqi2LxQcIttVVYDTwG/LaFc9T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M8Pd8ygAsJVzO6hposwptsZJ6gI6YIT5B0pZGOtmeCXQDm4GPA78CLrDdJempQ+BzOOA84BZJ/Wwj7xafZBRNzzbYfhcwDtiWOm8m8lNrjHUag/C7SnoCeKSe8zij0PcDTxEUemKjc7QIjwD/Jrjl6h5P0rA9FbiLEImZEUOiywjv6+oW8awE4jl9DuF5+yHPQL8fy2XxD2zJoEcQVq4RwPdS8jfH8oqYXpbIj6ROSn8OLgO+nHVlVVmh8XL2c4IbLDc52fYkwqrbC5whaWcc5y7gD8Ds6B2pJGx/2na37W7CXQBgSlJn+9qcIZYAq+rlKQxooJIeBlYB44HNttfYXkU4k80mXACuSck/RPB9TgAet706Evwz8AaCE7bh27Wk5wmKnpfUHSYK7QFeAh4aSCjuQr8ghPdm1LgQdsQy7xxeJiYRvDfzCSmFEAI0Sd3ceh1jgtK+dKAli9wtV9LltjcStqzzCM72pwkr1nU1bswLgScJkaQv8WokaSlhxWto20vNv932rfGBGlHoeoJCTxvMPAVjHXBznjdB0lbC2ble+30MQU6CpG7CcamZvp3khHEHwC5JA+54bX19eRG4YmD73QQH/u2S+qX2D2MYtVB4NlMMuY3I1L2R4NqB194f4YbRQrQim+kSwl9IHyT4SdsJbpNxhMvDnS2YcxivUbTCQNcTsp7OBMYQokdbCOloXQ1k9QxjGAcwZGfQYQyjGfwfMWiio3c1OAQAAAAASUVORK5CYII=\n",
"text/latex": [
"$\\displaystyle \\log{\\left(x + \\sqrt{x^{2} + 1} \\right)}$"
],
"text/plain": [
" ⎛ ________⎞\n",
" ⎜ ╱ 2 ⎟\n",
"log⎝x + ╲╱ x + 1 ⎠"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x = symbols('x')\n",
"asinh(x).rewrite('log')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"________\n",
"$$\\displaystyle \\textbf{Table of inverse functions}\\quad i=\\sqrt{-1}\\\\\n",
"\\begin{array}{lll}\n",
"\\hline\n",
"\\sin^{-1}(x) &= -i\\log(ix +\\sqrt{1-x^2} )\\\\\n",
"\\cos^{-1}(x) &= +i\\log(ix +\\sqrt{1-x^2} ) + \\frac{\\pi}{2}\\\\\n",
"\\tan^{-1}(x) &= \\frac{i}{2}\\left( \\log(1-ix)- \\log(1+ix ) \\right)\\\\\n",
"\\sinh^{-1}(x) & = \\log(x+\\sqrt{1+x^2})\\\\\n",
"\\cosh^{-1}(x) & = \\log(x+\\sqrt{x^2-1})\\\\\n",
"\\tanh^{-1}(x) & =\\frac{1}{2} \\log(x+1)-\\frac{1}{2}\\log(1-x)\\\\\n",
"\\hline\\end{array}$$\n",
"________\n",
"\n",
"![Drawing](chapter1-fig16.png)\n",
"\n",
"Figure 16. Inverse trig functions with $y$ limited to the range $\\pm 2 \\pi$. The $\\tan^{-1}$ functions extend to $x = \\pm\\infty$ with a limit of integer multiples of $y = \\pm \\pi/2$.\n",
"_________\n",
"\n",
"## 7 Cartesian and polar coordinates\n",
"\n",
"When drawing a graph a right-angled set of axes is normally used. The origin is the point (0, 0) and then any other point is represented by two numbers $(x,\\; y)$ in the x-y plane. In three dimensions the coordinates are $(x,\\; y,\\; z)$. These coordinates are described as rectilinear when right-angled axes are used and as Cartesian when $(x,\\; y,\\; z)$ are used.\n",
"\n",
"There are other ways of defining a point in space and some of them will be used when the situation requires it. In crystallography, for example, it is often sensible to define axes of particular crystal types that are not always at 90$^\\text{o}$ to one another and of unequal length. Monoclinic and trigonal crystal types, among others, have these 'sloping' axes. On the surface of a sphere, such as the earth, there are no straight lines, and latitude and longitude, which are angles, are used to define a location. In other situations, for example defining the three-dimensional shapes of atomic orbitals, spherical polar coordinates are used and in these coordinates, two angles and a radius define a point. These coordinates are used because they reflect the underlying symmetry of the problem and equations become easier to solve. In the hydrogen molecule, prolate spheroidal coordinates are used. These have two origins, one at each atom, see Figure 30 for a sketch of coordinates. In other situations, cylindrical coordinates are used. There are many other coordinate systems, see Arkfen (1970) for a description.\n",
"\n",
"The reason for using different coordinate systems is not to make life difficult, far from it, but is that calculations are often easier done in these coordinates than in Cartesians; the disadvantage of these other coordinate systems is only unfamiliarity. In each case, it is possible to convert from one coordinate 'system' to another. In spherical polar coordinates the radius $r$ is the distance of a point from the origin, $\\theta$ is the polar angle measured from the z-axis and $\\phi$ the azimuthal or equatorial angle measured in the x-y plane from the x- to the y-axis. The conversion between Cartesian and _spherical polar_ coordinates is\n",
"\n",
"$$\\displaystyle \\begin{align} x &= r \\sin(\\theta)\\cos(\\phi),\\qquad &y = r \\sin(\\theta)\\sin(\\phi)\\\\\n",
"z&=r\\cos(\\theta), \\qquad &r^2 =x^2 +y^2 +z^2\\end{align}$$\n",
"\n",
"The azimuthal angle $\\phi$ is in the $x-y$ plane and measures the angle from the x-axis to the line formed by the projection of the point onto this plane, and has a maximum of 360$^\\text{o}$. $\\theta$ is the polar angle measured from 0 to 180$^\\text{o}$ from the z-axis. Sometimes when doing an integration it is advantageous to change coordinates from $xyz$ to spherical polar ones. The volume element $dxdydx$ then becomes $r^2\\sin(\\theta)drd\\theta d\\phi$ and the limits on the integration are also changed to $0\\to 2\\pi$ for $\\phi$, $0\\to \\pi$ for $\\theta$ and $0\\to \\infty$ for $r$. How the volume element is formed is shown using Jacobian determinants in Chapter 4, section 10.11. \n",
"\n",
"![Drawing](chapter1-fig17.png)\n",
"\n",
"Figure 17 Spherical polar coordinates. The point at $(x,\\; y,\\; z)$ in Cartesian coordinates is at $(r,\\; \\theta, \\; \\phi)$ in spherical polar coordinates. \n",
"\n",
"In two dimensions, _plane polar_ coordinates are used to define a point in the x-y plane. If z is included then these coordinates become the cylindrical coordinates. The relationship of plane polar to Cartesian coordinates is\n",
"\n",
"$$\\displaystyle x=r\\cos(\\theta),\\quad y=r\\sin(\\theta), \\quad r^2 =x^2 +y^2$$\n",
"\n",
"The angle $\\theta$ is measured from the x- to the y-axis, figure 18. The volume element used in integrations is changed as $dxdy \\to rdrd\\theta$ and the integration limits fro $\\pm\\infty$ to $0\\to \\infty$ in $r$ and $0\\to 2\\pi$ in $\\theta$. (Note that $\\theta$ is defined differently than that in spherical polar coordinates).\n",
"\n",
"![Drawing](chapter1-fig18.png)\n",
"\n",
"Figure 18. Plane polar coordinates.\n",
"_______"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 8 Factorials, Stirling's formula, gamma function\n",
"\n",
"The factorial function is the product of a set of _positive integers_ from 1 up to n;\n",
"\n",
"$$\\displaystyle n! = n \\times (n - 1) \\times (n - 2) \\times \\cdots \\times 2 \\times 1 $$\n",
"\n",
"with the limits that\n",
"\n",
"$$\\displaystyle 0! = 1,\\qquad (-n)! \\to \\infty$$\n",
"\n",
"The factorials can also be calculated recursively as \n",
"\n",
"$$\\displaystyle (n + 1)! = (n + 1)n!$$\n",
"\n",
"In Figure 19 notice how rapidly the factorials increase as $n$ increases. The plot is of $\\ln(n!)$ vs $n$, which shows that $n!$ increases more rapidly than does $e^{n}$, which would be a line of slope 1 on this graph.\n",
"\n",
"Fractional, negative, and complex factorials are defined by the (complete) gamma function $\\Gamma(n)$. Positive integer values of this function produce the factorials, and are related as \n",
"\n",
"$$\\displaystyle \\Gamma(n) = (n - 1)!$$\n",
"\n",
"The Gamma Function is the integral \n",
"\n",
"$$\\displaystyle \\Gamma(z) = \\int_0^\\infty t^{z-1}e^{-t}dt$$\n",
"\n",
"which is defined in Python using a special function and imported as $\\mathtt{from\\,scipy.special \\,import \\,gamma}$. This can then be used to calculate any factorials such as shown in the figure.\n",
"\n",
"Occasionally you may come across double factorials defined as \n",
"\n",
"$$\\displaystyle n!! = n(n - 2)(n - 4) \\cdots 5 \\cdot 3 \\cdot 1$$\n",
"\n",
"if $n$ is a positive odd integer and\n",
"\n",
"$$\\displaystyle n!! = n(n - 2)(n - 4) \\cdots 6 \\cdot 4 \\cdot 2 $$\n",
"\n",
"if $n$ is a positive even integer and $n!! = 1$ if $n$ is $-1$ or $0$. \n",
"\n",
"A ratio of factorials arises from the series \n",
"\n",
"$$ x(x+1)(x+2)\\cdots (x+n-1)=\\frac{(x+n-1)!}{(x-1)!} \\qquad\\tag{17}$$\n",
"\n",
"is sometimes given the symbol $(x)_n$ which is called the Pochhammer symbol, although this notation is not universal. Ratios of factorials similar to these occur in quantum mechanics, particularly when angular momentum quantum numbers are involved.\n",
"\n",
"### **(i) Large factorials. Stirling's formula**\n",
"\n",
"The log of the factorial is often used as a way of calculating factorials for large $n$ particularly those too large for normal multiplication. To this end Stirling's formula,\n",
"\n",
"$$\\displaystyle \\ln(n!) = n \\ln(n) - n \\qquad\\tag{18}$$\n",
"\n",
"is particularly useful. For smaller values we can use the equivalent formula $\\displaystyle n! = n^ne^{-n}$.\n",
"\n",
"The approximations is calculated as\n",
"\n",
"$$\\displaystyle \\begin{align}\\ln(n!)&=\\sum_{j=1}^n \\ln(n_j) \\approx \\int_1^n \\ln(x)dx=(n\\ln(n)-n)\\big|_1^n\\\\ &= n \\ln(n) - n+1\\end{align} $$\n",
"\n",
"which is slightly smaller than the true value. A far more accurate approximation, if such is needed, is \n",
"\n",
"$$\\displaystyle \\ln(n!) = \\left(n+\\frac{1}{2}\\right) \\ln(n) - n +\\frac{1}{2}\\ln(2\\pi)$$\n",
"\n",
"which on the scale of figure 19 produces values indistinguishable from the true values.\n",
"\n",
"![Drawing](chapter1-fig19.png) \n",
" \n",
" Figure 19. Left: $\\ln(n!)$ vs $n$. The curve is not smooth because the factorials are integer numbers. Right: The gamma function (solid line) and the factorial (circles).\n",
" _____\n",
" \n",
"## 8.1 Recursion. Calculating Factorials and Orthogonal Polynomials.\n",
"\n",
"Recursion is a general method by which certain functions, such as a factorial or a polynomial, can be calculated by starting with one or two values and using these as a seed to generate further values. The recursion equations are sometimes also called difference equations. \n",
"\n",
"The algorithms to calculate the square root, $e$, and $\\pi$ are each recursive because a previous result is used to calculate the next one. The factorial is the product of numbers separated by unit values, so starting with one value and an increment, all the rest can be calculated up to a given number. The equation is \n",
"\n",
"$$\\displaystyle (n + 1)! = (n + 1)n!$$\n",
"\n",
"An algorithm to calculate factorials up to a value of $n$, is"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1307674368000\n"
]
}
],
"source": [
"#### Algorithm. Direct calculation of a factorial \n",
"#-----------------\n",
"def fact(n):\n",
" if n <= 1 :\n",
" return 1\n",
" f = 1\n",
" for i in range(1,n+1):\n",
" f = f*i\n",
" return f\n",
"#-----------------\n",
"print(fact(15))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"returns $1307674368000$. In fact the Python language allows the function $\\mathtt{fact(n)}$ itself to be recursive as shown in the next algorithm. It is perhaps more intuitive since the factorial can be defined as $(n + 1 )! = (n + 1)n!$ or as $n! = n(n-1)!$ which is the form used in the next algorithm."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1307674368000\n"
]
}
],
"source": [
"#### Algorithm. Recursive function calculation of factorial\n",
"#---------------------\n",
"def fact(n):\n",
" if n <= 1 :\n",
" return 1\n",
" return n*fact(n-1)\n",
"#---------------------\n",
"print(fact(15))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The polynomials used to define wavefunctions in quantum mechanics can be calculated by recursion and while there are other ways of calculating them, such as the generating function method, see Chapter 9, recursion is often convenient. The Hermite polynomials $H_n(x)$ describe part of the wavefunctions of the Quantum Harmonic Oscillator, as used to describe vibrations of a molecule, and the other parts multiply the Hermite by a normalization constant and by $e^{-x^2/2}$. In the Hermite polynomial, $n$ is an integer $n \\ge 0$ representing the quantum number, and $x$ is proportional to the displacement of the oscillator from equilibrium. The wavefunction's equation is \n",
"\n",
"$$\\displaystyle \\psi _{n}(x)={\\frac {1}{\\sqrt {2^{n}\\,n!}}} \\left({\\frac {m\\omega }{\\pi \\hbar }}\\right)^{1/4} e^{-{{m\\omega x^{2}}/{2\\hbar }}} H_{n}\\left({\\sqrt {\\frac {m\\omega }{\\hbar }}}\\,x\\right),\\qquad n=0,1,2,\\cdots \\qquad\\tag{18a}$$\n",
"\n",
"where $m$ is the mass and $\\omega=2\\pi v$ the frequency.\n",
"\n",
"One recursion formula for the Hermite when $n \\ge 1$ is\n",
"\n",
"$$\\displaystyle H_{n+1}(x) = 2xH_n(x) - 2nH_{n-1}(x); \\qquad H_0(x) = 1\\qquad \\text{and}\\qquad H_1(x) = 2x$$\n",
"\n",
"The next value with $n = 1$, is \n",
"\n",
"$$\\displaystyle H_2(x) = 2xH_1(x) - 2H_0(x) = 4x^2 - 2$$\n",
"\n",
"All other values can be obtained in a similar way using the recursion formula given above. Using Sympy this can be automated"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAooAAAAUCAYAAAAKhxyWAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAABJ0AAASdAHeZh94AAANz0lEQVR4nO2deZAdVRXGfwHUUkRQVnErRMKi4uACBKIkIgEDQhAsSwokyKIESMISdjx8WkhQCAlbsahMiFSBspURZEdZBYGgYEAQCIgkYQ3FImBg/OP0SzqdfvP63vf6vTcz/VVN9by+3eeevt89596+y+lhfX19VKhQoUKFChUqVKiQxUqdVqAbIOlrwBHAl4B1gX3MrDfnugnAFOCjwD+AyWZ2WxtVrRAISSsCJwJ74rzNBy4GTjSzxR1UrUIJkPRRYCowFlgFeAI40Mz+3FHFKpQKSccAPwPONrODO61PhdYi4ffbwIbAW8BfgGPM7KGOKjZEsEKnFegSfBB4CJgE/DfvAknfBWbgzmgz4E7gj5I+2S4lK0ThKOAgYCKwEc7xQcAxnVSqQushaTXgDmAYsCOwMXAI8FwH1apQMiRtCRwA/L3TulQoDaOAc4CtgK8Di4EbJX2kk0oNFVQjioCZXQNcAyCpt85lhwG9ZnZB8vsQSTsAB1J1OroZWwGzzWx28nuepN8DW3RQpw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+ 161280 x^{6} - 403200 x^{4} + 302400 x^{2} - 30240$"
],
"text/plain": [
" 10 8 6 4 2 \n",
"1024⋅x - 23040⋅x + 161280⋅x - 403200⋅x + 302400⋅x - 30240"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#### Algorithm. Hermite Polynomial Recursion. (This is slow for large n )\n",
"\n",
"x, n = symbols('x, n') # define n and x in SymPy\n",
"\n",
"#----------------------\n",
"def herm(n, x): # define recursion equations returns the nth hermite with argument x \n",
" if n == 0:\n",
" return 1 \n",
" elif n == 1: \n",
" return 2*x \n",
" else: \n",
" return (2*x*herm(n - 1, x)) - 2*(n- 1)*herm(n - 2, x) \n",
"#---------------------- \n",
"expand(herm(10,x)) # return 10th Hermite as polynomial"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}