From 43ba3a8c82f310bf861b8a1472ce1be89fce741f Mon Sep 17 00:00:00 2001 From: Morten Hjorth-Jensen Date: Thu, 27 Oct 2022 08:49:01 +0200 Subject: [PATCH] update week 43 --- doc/pub/week43/html/week43-bs.html | 314 +------ doc/pub/week43/html/week43-reveal.html | 311 +------ doc/pub/week43/html/week43-solarized.html | 308 +------ doc/pub/week43/html/week43.html | 308 +------ doc/pub/week43/ipynb/ipynb-week43-src.tar.gz | Bin 88085 -> 88085 bytes doc/pub/week43/ipynb/week43.ipynb | 879 +++++-------------- doc/src/week43/week43.do.txt | 218 ----- 7 files changed, 252 insertions(+), 2086 deletions(-) diff --git a/doc/pub/week43/html/week43-bs.html b/doc/pub/week43/html/week43-bs.html index 34de8bd38..2b5b637fa 100644 --- a/doc/pub/week43/html/week43-bs.html +++ b/doc/pub/week43/html/week43-bs.html @@ -74,25 +74,6 @@ doconce format html week43.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'a-more-efficient-way-of-coding-the-above-convolution'), - ('Convolution Examples: Principle of Superposition and Periodic ' - 'Forces (Fourier Transforms)', - 2, - None, - 'convolution-examples-principle-of-superposition-and-periodic-forces-fourier-transforms'), - ('Principle of Superposition', - 2, - None, - 'principle-of-superposition'), - ('Simple Code Example', 2, None, 'simple-code-example'), - ('Wrapping up Fourier transforms', - 2, - None, - 'wrapping-up-fourier-transforms'), - ('Finding the Coefficients', 2, None, 'finding-the-coefficients'), - ('Final words on Fourier Transforms', - 2, - None, - 'final-words-on-fourier-transforms'), ('Two-dimensional Objects', 2, None, 'two-dimensional-objects'), ('Cross-Correlation', 2, None, 'cross-correlation'), ('More on Dimensionalities', 2, None, 'more-on-dimensionalities'), @@ -233,12 +214,6 @@ MathJax.Hub.Config({
  • Convolution Examples: Polynomial multiplication
  • Efficient Polynomial Multiplication
  • A more efficient way of coding the above Convolution
  • -
  • Convolution Examples: Principle of Superposition and Periodic Forces (Fourier Transforms)
  • -
  • Principle of Superposition
  • -
  • Simple Code Example
  • -
  • Wrapping up Fourier transforms
  • -
  • Finding the Coefficients
  • -
  • Final words on Fourier Transforms
  • Two-dimensional Objects
  • Cross-Correlation
  • More on Dimensionalities
  • @@ -311,7 +286,7 @@ MathJax.Hub.Config({
    -

    Oct 26, 2022

    +

    Oct 27, 2022


    @@ -712,279 +687,6 @@ We rather code the convolutions in the minimal memory footprint that they requir

    Does the number of floating point operations change here when we use the commutative property?

    - -

    Convolution Examples: Principle of Superposition and Periodic Forces (Fourier Transforms)

    - -

    For problems with so-called harmonic oscillations, given by for example the following differential equation

    -$$ -m\frac{d^2x}{dt^2}+\eta\frac{dx}{dt}+x(t)=F(t), -$$ - -

    where \( F(t) \) is an applied external force acting on the system (often called a driving force), one can use the theory of Fourier transformations to find the solutions of this type of equations.

    - -

    If one has several driving forces, \( F(t)=\sum_n F_n(t) \), one can find -the particular solution to each \( F_n \), \( x_{pn}(t) \), and the particular -solution for the entire driving force is then given by a series like -

    - -$$ -\begin{equation} -x_p(t)=\sum_nx_{pn}(t). -\label{_auto1} -\end{equation} -$$ - - - -

    Principle of Superposition

    - -

    This is known as the principle of superposition. It only applies when -the homogenous equation is linear. If there were an anharmonic term -such as \( x^3 \) in the homogenous equation, then when one summed various -solutions, \( x=(\sum_n x_n)^2 \), one would get cross -terms. Superposition is especially useful when \( F(t) \) can be written -as a sum of sinusoidal terms, because the solutions for each -sinusoidal (sine or cosine) term is analytic. -

    - -

    Driving forces are often periodic, even when they are not -sinusoidal. Periodicity implies that for some time \( \tau \) -

    - -$$ -\begin{eqnarray} -F(t+\tau)=F(t). -\end{eqnarray} -$$ - -

    One example of a non-sinusoidal periodic force is a square wave. Many -components in electric circuits are non-linear, e.g. diodes, which -makes many wave forms non-sinusoidal even when the circuits are being -driven by purely sinusoidal sources. -

    - - -

    Simple Code Example

    - -

    The code here shows a typical example of such a square wave generated using the functionality included in the scipy Python package. We have used a period of \( \tau=0.2 \).

    - - - -
    -
    -
    -
    -
    -
    import numpy as np
    -import math
    -from scipy import signal
    -import matplotlib.pyplot as plt
    -
    -# number of points                                                                                       
    -n = 500
    -# start and final times                                                                                  
    -t0 = 0.0
    -tn = 1.0
    -# Period                                                                                                 
    -t = np.linspace(t0, tn, n, endpoint=False)
    -SqrSignal = np.zeros(n)
    -SqrSignal = 1.0+signal.square(2*np.pi*5*t)
    -plt.plot(t, SqrSignal)
    -plt.ylim(-0.5, 2.5)
    -plt.show()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    For the sinusoidal example the -period is \( \tau=2\pi/\omega \). However, higher harmonics can also -satisfy the periodicity requirement. In general, any force that -satisfies the periodicity requirement can be expressed as a sum over -harmonics, -

    - -$$ -\begin{equation} -F(t)=\frac{f_0}{2}+\sum_{n>0} f_n\cos(2n\pi t/\tau)+g_n\sin(2n\pi t/\tau). -\label{_auto2} -\end{equation} -$$ - - - -

    Wrapping up Fourier transforms

    - -

    We can write down the answer for -\( x_{pn}(t) \), by substituting \( f_n/m \) or \( g_n/m \) for \( F_0/m \). By -writing each factor \( 2n\pi t/\tau \) as \( n\omega t \), with \( \omega\equiv -2\pi/\tau \), -

    - -$$ -\begin{equation} -\label{eq:fourierdef1} -F(t)=\frac{f_0}{2}+\sum_{n>0}f_n\cos(n\omega t)+g_n\sin(n\omega t). -\end{equation} -$$ - -

    The solutions for \( x(t) \) then come from replacing \( \omega \) with -\( n\omega \) for each term in the particular solution, -

    - -$$ -\begin{eqnarray} -x_p(t)&=&\frac{f_0}{2k}+\sum_{n>0} \alpha_n\cos(n\omega t-\delta_n)+\beta_n\sin(n\omega t-\delta_n),\\ -\nonumber -\alpha_n&=&\frac{f_n/m}{\sqrt{((n\omega)^2-\omega_0^2)+4\beta^2n^2\omega^2}},\\ -\nonumber -\beta_n&=&\frac{g_n/m}{\sqrt{((n\omega)^2-\omega_0^2)+4\beta^2n^2\omega^2}},\\ -\nonumber -\delta_n&=&\tan^{-1}\left(\frac{2\beta n\omega}{\omega_0^2-n^2\omega^2}\right). -\end{eqnarray} -$$ - - - -

    Finding the Coefficients

    - -

    Because the forces have been applied for a long time, any non-zero -damping eliminates the homogenous parts of the solution, so one need -only consider the particular solution for each \( n \). -

    - -

    The problem is considered solved if one can find expressions for the -coefficients \( f_n \) and \( g_n \), even though the solutions are expressed -as an infinite sum. The coefficients can be extracted from the -function \( F(t) \) by -

    - -$$ -\begin{eqnarray} -\label{eq:fourierdef2} -f_n&=&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~F(t)\cos(2n\pi t/\tau),\\ -\nonumber -g_n&=&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~F(t)\sin(2n\pi t/\tau). -\end{eqnarray} -$$ - -

    To check the consistency of these expressions and to verify -Eq. \eqref{eq:fourierdef2}, one can insert the expansion of \( F(t) \) in -Eq. \eqref{eq:fourierdef1} into the expression for the coefficients in -Eq. \eqref{eq:fourierdef2} and see whether -

    - -$$ -\begin{eqnarray} -f_n&=?&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~\left\{ -\frac{f_0}{2}+\sum_{m>0}f_m\cos(m\omega t)+g_m\sin(m\omega t) -\right\}\cos(n\omega t). -\end{eqnarray} -$$ - -

    Immediately, one can throw away all the terms with \( g_m \) because they -convolute an even and an odd function. The term with \( f_0/2 \) -disappears because \( \cos(n\omega t) \) is equally positive and negative -over the interval and will integrate to zero. For all the terms -\( f_m\cos(m\omega t) \) appearing in the sum, one can use angle addition -formulas to see that \( \cos(m\omega t)\cos(n\omega -t)=(1/2)(\cos[(m+n)\omega t]+\cos[(m-n)\omega t] \). This will integrate -to zero unless \( m=n \). In that case the \( m=n \) term gives -

    - -$$ -\begin{equation} -\int_{-\tau/2}^{\tau/2}dt~\cos^2(m\omega t)=\frac{\tau}{2}, -\label{_auto3} -\end{equation} -$$ - -

    and

    - -$$ -\begin{eqnarray} -f_n&=?&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~f_n/2\\ -\nonumber -&=&f_n~\checkmark. -\end{eqnarray} -$$ - -

    The same method can be used to check for the consistency of \( g_n \).

    - - -

    Final words on Fourier Transforms

    - -

    The code here uses the Fourier series applied to a -square wave signal. The code here -visualizes the various approximations given by Fourier series compared -with a square wave with period \( T=0.2 \) (dimensionless time), width \( 0.1 \) and max value of the force \( F=2 \). We -see that when we increase the number of components in the Fourier -series, the Fourier series approximation gets closer and closer to the -square wave signal. -

    - - - -
    -
    -
    -
    -
    -
    import numpy as np
    -import math
    -from scipy import signal
    -import matplotlib.pyplot as plt
    -
    -# number of points                                                                                       
    -n = 500
    -# start and final times                                                                                  
    -t0 = 0.0
    -tn = 1.0
    -# Period                                                                                                 
    -T =0.2
    -# Max value of square signal                                                                             
    -Fmax= 2.0
    -# Width of signal   
    -Width = 0.1
    -t = np.linspace(t0, tn, n, endpoint=False)
    -SqrSignal = np.zeros(n)
    -FourierSeriesSignal = np.zeros(n)
    -SqrSignal = 1.0+signal.square(2*np.pi*5*t+np.pi*Width/T)
    -a0 = Fmax*Width/T
    -FourierSeriesSignal = a0
    -Factor = 2.0*Fmax/np.pi
    -for i in range(1,500):
    -    FourierSeriesSignal += Factor/(i)*np.sin(np.pi*i*Width/T)*np.cos(i*t*2*np.pi/T)
    -plt.plot(t, SqrSignal)
    -plt.plot(t, FourierSeriesSignal)
    -plt.ylim(-0.5, 2.5)
    -plt.show()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    Two-dimensional Objects

    @@ -2483,7 +2185,7 @@ samples $$ \begin{equation} x = g(z; \theta^{(g)}) -\label{_auto4} +\label{_auto1} \end{equation} $$ @@ -2500,7 +2202,7 @@ value given by $$ \begin{equation} d(x; \theta^{(d)}) -\label{_auto5} +\label{_auto2} \end{equation} $$ @@ -2513,7 +2215,7 @@ which a function $$ \begin{equation} v(\theta^{(g)}, \theta^{(d)}) -\label{_auto6} +\label{_auto3} \end{equation} $$ @@ -2524,7 +2226,7 @@ conjugate reward $$ \begin{equation} -v(\theta^{(g)}, \theta^{(d)}) -\label{_auto7} +\label{_auto4} \end{equation} $$ @@ -2559,7 +2261,7 @@ $$ \begin{equation} g^* = \underset{g}{\mathrm{argmin}}\hspace{2pt} \underset{d}{\mathrm{max}}v(\theta^{(g)}, \theta^{(d)}) -\label{_auto8} +\label{_auto5} \end{equation} $$ @@ -2569,7 +2271,7 @@ $$ v(\theta^{(g)}, \theta^{(d)}) = \mathbb{E}_{x\sim p_\mathrm{data}}\log d(x) + \mathbb{E}_{x\sim p_\mathrm{model}} \log (1 - d(x)) -\label{_auto9} +\label{_auto6} \end{equation} $$ @@ -2580,7 +2282,7 @@ approximation of a partition function. In the case where $$ \begin{equation} \underset{d}{\mathrm{max}}v(\theta^{(g)}, \theta^{(d)}) -\label{_auto10} +\label{_auto7} \end{equation} $$ diff --git a/doc/pub/week43/html/week43-reveal.html b/doc/pub/week43/html/week43-reveal.html index 8aa64732d..d1a52efbd 100644 --- a/doc/pub/week43/html/week43-reveal.html +++ b/doc/pub/week43/html/week43-reveal.html @@ -184,7 +184,7 @@ MathJax.Hub.Config({
    -

    Oct 26, 2022

    +

    Oct 27, 2022


    @@ -623,301 +623,6 @@ We rather code the convolutions in the minimal memory footprint that they requir

    Does the number of floating point operations change here when we use the commutative property?

    -
    -

    Convolution Examples: Principle of Superposition and Periodic Forces (Fourier Transforms)

    - -

    For problems with so-called harmonic oscillations, given by for example the following differential equation

    -

     
    -$$ -m\frac{d^2x}{dt^2}+\eta\frac{dx}{dt}+x(t)=F(t), -$$ -

     
    - -

    where \( F(t) \) is an applied external force acting on the system (often called a driving force), one can use the theory of Fourier transformations to find the solutions of this type of equations.

    - -

    If one has several driving forces, \( F(t)=\sum_n F_n(t) \), one can find -the particular solution to each \( F_n \), \( x_{pn}(t) \), and the particular -solution for the entire driving force is then given by a series like -

    - -

     
    -$$ -\begin{equation} -x_p(t)=\sum_nx_{pn}(t). -\tag{1} -\end{equation} -$$ -

     
    -

    - -
    -

    Principle of Superposition

    - -

    This is known as the principle of superposition. It only applies when -the homogenous equation is linear. If there were an anharmonic term -such as \( x^3 \) in the homogenous equation, then when one summed various -solutions, \( x=(\sum_n x_n)^2 \), one would get cross -terms. Superposition is especially useful when \( F(t) \) can be written -as a sum of sinusoidal terms, because the solutions for each -sinusoidal (sine or cosine) term is analytic. -

    - -

    Driving forces are often periodic, even when they are not -sinusoidal. Periodicity implies that for some time \( \tau \) -

    - -

     
    -$$ -\begin{eqnarray} -F(t+\tau)=F(t). -\end{eqnarray} -$$ -

     
    - -

    One example of a non-sinusoidal periodic force is a square wave. Many -components in electric circuits are non-linear, e.g. diodes, which -makes many wave forms non-sinusoidal even when the circuits are being -driven by purely sinusoidal sources. -

    -
    - -
    -

    Simple Code Example

    - -

    The code here shows a typical example of such a square wave generated using the functionality included in the scipy Python package. We have used a period of \( \tau=0.2 \).

    - - - -
    -
    -
    -
    -
    -
    import numpy as np
    -import math
    -from scipy import signal
    -import matplotlib.pyplot as plt
    -
    -# number of points                                                                                       
    -n = 500
    -# start and final times                                                                                  
    -t0 = 0.0
    -tn = 1.0
    -# Period                                                                                                 
    -t = np.linspace(t0, tn, n, endpoint=False)
    -SqrSignal = np.zeros(n)
    -SqrSignal = 1.0+signal.square(2*np.pi*5*t)
    -plt.plot(t, SqrSignal)
    -plt.ylim(-0.5, 2.5)
    -plt.show()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    For the sinusoidal example the -period is \( \tau=2\pi/\omega \). However, higher harmonics can also -satisfy the periodicity requirement. In general, any force that -satisfies the periodicity requirement can be expressed as a sum over -harmonics, -

    - -

     
    -$$ -\begin{equation} -F(t)=\frac{f_0}{2}+\sum_{n>0} f_n\cos(2n\pi t/\tau)+g_n\sin(2n\pi t/\tau). -\tag{2} -\end{equation} -$$ -

     
    -

    - -
    -

    Wrapping up Fourier transforms

    - -

    We can write down the answer for -\( x_{pn}(t) \), by substituting \( f_n/m \) or \( g_n/m \) for \( F_0/m \). By -writing each factor \( 2n\pi t/\tau \) as \( n\omega t \), with \( \omega\equiv -2\pi/\tau \), -

    - -

     
    -$$ -\begin{equation} -\tag{3} -F(t)=\frac{f_0}{2}+\sum_{n>0}f_n\cos(n\omega t)+g_n\sin(n\omega t). -\end{equation} -$$ -

     
    - -

    The solutions for \( x(t) \) then come from replacing \( \omega \) with -\( n\omega \) for each term in the particular solution, -

    - -

     
    -$$ -\begin{eqnarray} -x_p(t)&=&\frac{f_0}{2k}+\sum_{n>0} \alpha_n\cos(n\omega t-\delta_n)+\beta_n\sin(n\omega t-\delta_n),\\ -\nonumber -\alpha_n&=&\frac{f_n/m}{\sqrt{((n\omega)^2-\omega_0^2)+4\beta^2n^2\omega^2}},\\ -\nonumber -\beta_n&=&\frac{g_n/m}{\sqrt{((n\omega)^2-\omega_0^2)+4\beta^2n^2\omega^2}},\\ -\nonumber -\delta_n&=&\tan^{-1}\left(\frac{2\beta n\omega}{\omega_0^2-n^2\omega^2}\right). -\end{eqnarray} -$$ -

     
    -

    - -
    -

    Finding the Coefficients

    - -

    Because the forces have been applied for a long time, any non-zero -damping eliminates the homogenous parts of the solution, so one need -only consider the particular solution for each \( n \). -

    - -

    The problem is considered solved if one can find expressions for the -coefficients \( f_n \) and \( g_n \), even though the solutions are expressed -as an infinite sum. The coefficients can be extracted from the -function \( F(t) \) by -

    - -

     
    -$$ -\begin{eqnarray} -\tag{4} -f_n&=&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~F(t)\cos(2n\pi t/\tau),\\ -\nonumber -g_n&=&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~F(t)\sin(2n\pi t/\tau). -\end{eqnarray} -$$ -

     
    - -

    To check the consistency of these expressions and to verify -Eq. (4), one can insert the expansion of \( F(t) \) in -Eq. (3) into the expression for the coefficients in -Eq. (4) and see whether -

    - -

     
    -$$ -\begin{eqnarray} -f_n&=?&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~\left\{ -\frac{f_0}{2}+\sum_{m>0}f_m\cos(m\omega t)+g_m\sin(m\omega t) -\right\}\cos(n\omega t). -\end{eqnarray} -$$ -

     
    - -

    Immediately, one can throw away all the terms with \( g_m \) because they -convolute an even and an odd function. The term with \( f_0/2 \) -disappears because \( \cos(n\omega t) \) is equally positive and negative -over the interval and will integrate to zero. For all the terms -\( f_m\cos(m\omega t) \) appearing in the sum, one can use angle addition -formulas to see that \( \cos(m\omega t)\cos(n\omega -t)=(1/2)(\cos[(m+n)\omega t]+\cos[(m-n)\omega t] \). This will integrate -to zero unless \( m=n \). In that case the \( m=n \) term gives -

    - -

     
    -$$ -\begin{equation} -\int_{-\tau/2}^{\tau/2}dt~\cos^2(m\omega t)=\frac{\tau}{2}, -\tag{5} -\end{equation} -$$ -

     
    - -

    and

    - -

     
    -$$ -\begin{eqnarray} -f_n&=?&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~f_n/2\\ -\nonumber -&=&f_n~\checkmark. -\end{eqnarray} -$$ -

     
    - -

    The same method can be used to check for the consistency of \( g_n \).

    -
    - -
    -

    Final words on Fourier Transforms

    - -

    The code here uses the Fourier series applied to a -square wave signal. The code here -visualizes the various approximations given by Fourier series compared -with a square wave with period \( T=0.2 \) (dimensionless time), width \( 0.1 \) and max value of the force \( F=2 \). We -see that when we increase the number of components in the Fourier -series, the Fourier series approximation gets closer and closer to the -square wave signal. -

    - - - -
    -
    -
    -
    -
    -
    import numpy as np
    -import math
    -from scipy import signal
    -import matplotlib.pyplot as plt
    -
    -# number of points                                                                                       
    -n = 500
    -# start and final times                                                                                  
    -t0 = 0.0
    -tn = 1.0
    -# Period                                                                                                 
    -T =0.2
    -# Max value of square signal                                                                             
    -Fmax= 2.0
    -# Width of signal   
    -Width = 0.1
    -t = np.linspace(t0, tn, n, endpoint=False)
    -SqrSignal = np.zeros(n)
    -FourierSeriesSignal = np.zeros(n)
    -SqrSignal = 1.0+signal.square(2*np.pi*5*t+np.pi*Width/T)
    -a0 = Fmax*Width/T
    -FourierSeriesSignal = a0
    -Factor = 2.0*Fmax/np.pi
    -for i in range(1,500):
    -    FourierSeriesSignal += Factor/(i)*np.sin(np.pi*i*Width/T)*np.cos(i*t*2*np.pi/T)
    -plt.plot(t, SqrSignal)
    -plt.plot(t, FourierSeriesSignal)
    -plt.ylim(-0.5, 2.5)
    -plt.show()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -

    Two-dimensional Objects

    @@ -2439,7 +2144,7 @@ samples $$ \begin{equation} x = g(z; \theta^{(g)}) -\tag{6} +\tag{1} \end{equation} $$

     
    @@ -2458,7 +2163,7 @@ value given by $$ \begin{equation} d(x; \theta^{(d)}) -\tag{7} +\tag{2} \end{equation} $$

     
    @@ -2473,7 +2178,7 @@ which a function $$ \begin{equation} v(\theta^{(g)}, \theta^{(d)}) -\tag{8} +\tag{3} \end{equation} $$

     
    @@ -2486,7 +2191,7 @@ conjugate reward $$ \begin{equation} -v(\theta^{(g)}, \theta^{(d)}) -\tag{9} +\tag{4} \end{equation} $$

     
    @@ -2524,7 +2229,7 @@ $$ \begin{equation} g^* = \underset{g}{\mathrm{argmin}}\hspace{2pt} \underset{d}{\mathrm{max}}v(\theta^{(g)}, \theta^{(d)}) -\tag{10} +\tag{5} \end{equation} $$

     
    @@ -2536,7 +2241,7 @@ $$ v(\theta^{(g)}, \theta^{(d)}) = \mathbb{E}_{x\sim p_\mathrm{data}}\log d(x) + \mathbb{E}_{x\sim p_\mathrm{model}} \log (1 - d(x)) -\tag{11} +\tag{6} \end{equation} $$

     
    @@ -2549,7 +2254,7 @@ approximation of a partition function. In the case where $$ \begin{equation} \underset{d}{\mathrm{max}}v(\theta^{(g)}, \theta^{(d)}) -\tag{12} +\tag{7} \end{equation} $$

     
    diff --git a/doc/pub/week43/html/week43-solarized.html b/doc/pub/week43/html/week43-solarized.html index 40f7a9d2d..dc463f252 100644 --- a/doc/pub/week43/html/week43-solarized.html +++ b/doc/pub/week43/html/week43-solarized.html @@ -101,25 +101,6 @@ div.toc p,a { 2, None, 'a-more-efficient-way-of-coding-the-above-convolution'), - ('Convolution Examples: Principle of Superposition and Periodic ' - 'Forces (Fourier Transforms)', - 2, - None, - 'convolution-examples-principle-of-superposition-and-periodic-forces-fourier-transforms'), - ('Principle of Superposition', - 2, - None, - 'principle-of-superposition'), - ('Simple Code Example', 2, None, 'simple-code-example'), - ('Wrapping up Fourier transforms', - 2, - None, - 'wrapping-up-fourier-transforms'), - ('Finding the Coefficients', 2, None, 'finding-the-coefficients'), - ('Final words on Fourier Transforms', - 2, - None, - 'final-words-on-fourier-transforms'), ('Two-dimensional Objects', 2, None, 'two-dimensional-objects'), ('Cross-Correlation', 2, None, 'cross-correlation'), ('More on Dimensionalities', 2, None, 'more-on-dimensionalities'), @@ -247,7 +228,7 @@ MathJax.Hub.Config({

    -

    Oct 26, 2022

    +

    Oct 27, 2022


    @@ -641,279 +622,6 @@ We rather code the convolutions in the minimal memory footprint that they requir

    Does the number of floating point operations change here when we use the commutative property?

    -









    -

    Convolution Examples: Principle of Superposition and Periodic Forces (Fourier Transforms)

    - -

    For problems with so-called harmonic oscillations, given by for example the following differential equation

    -$$ -m\frac{d^2x}{dt^2}+\eta\frac{dx}{dt}+x(t)=F(t), -$$ - -

    where \( F(t) \) is an applied external force acting on the system (often called a driving force), one can use the theory of Fourier transformations to find the solutions of this type of equations.

    - -

    If one has several driving forces, \( F(t)=\sum_n F_n(t) \), one can find -the particular solution to each \( F_n \), \( x_{pn}(t) \), and the particular -solution for the entire driving force is then given by a series like -

    - -$$ -\begin{equation} -x_p(t)=\sum_nx_{pn}(t). -\label{_auto1} -\end{equation} -$$ - - -









    -

    Principle of Superposition

    - -

    This is known as the principle of superposition. It only applies when -the homogenous equation is linear. If there were an anharmonic term -such as \( x^3 \) in the homogenous equation, then when one summed various -solutions, \( x=(\sum_n x_n)^2 \), one would get cross -terms. Superposition is especially useful when \( F(t) \) can be written -as a sum of sinusoidal terms, because the solutions for each -sinusoidal (sine or cosine) term is analytic. -

    - -

    Driving forces are often periodic, even when they are not -sinusoidal. Periodicity implies that for some time \( \tau \) -

    - -$$ -\begin{eqnarray} -F(t+\tau)=F(t). -\end{eqnarray} -$$ - -

    One example of a non-sinusoidal periodic force is a square wave. Many -components in electric circuits are non-linear, e.g. diodes, which -makes many wave forms non-sinusoidal even when the circuits are being -driven by purely sinusoidal sources. -

    - -









    -

    Simple Code Example

    - -

    The code here shows a typical example of such a square wave generated using the functionality included in the scipy Python package. We have used a period of \( \tau=0.2 \).

    - - - -
    -
    -
    -
    -
    -
    import numpy as np
    -import math
    -from scipy import signal
    -import matplotlib.pyplot as plt
    -
    -# number of points                                                                                       
    -n = 500
    -# start and final times                                                                                  
    -t0 = 0.0
    -tn = 1.0
    -# Period                                                                                                 
    -t = np.linspace(t0, tn, n, endpoint=False)
    -SqrSignal = np.zeros(n)
    -SqrSignal = 1.0+signal.square(2*np.pi*5*t)
    -plt.plot(t, SqrSignal)
    -plt.ylim(-0.5, 2.5)
    -plt.show()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    For the sinusoidal example the -period is \( \tau=2\pi/\omega \). However, higher harmonics can also -satisfy the periodicity requirement. In general, any force that -satisfies the periodicity requirement can be expressed as a sum over -harmonics, -

    - -$$ -\begin{equation} -F(t)=\frac{f_0}{2}+\sum_{n>0} f_n\cos(2n\pi t/\tau)+g_n\sin(2n\pi t/\tau). -\label{_auto2} -\end{equation} -$$ - - -









    -

    Wrapping up Fourier transforms

    - -

    We can write down the answer for -\( x_{pn}(t) \), by substituting \( f_n/m \) or \( g_n/m \) for \( F_0/m \). By -writing each factor \( 2n\pi t/\tau \) as \( n\omega t \), with \( \omega\equiv -2\pi/\tau \), -

    - -$$ -\begin{equation} -\label{eq:fourierdef1} -F(t)=\frac{f_0}{2}+\sum_{n>0}f_n\cos(n\omega t)+g_n\sin(n\omega t). -\end{equation} -$$ - -

    The solutions for \( x(t) \) then come from replacing \( \omega \) with -\( n\omega \) for each term in the particular solution, -

    - -$$ -\begin{eqnarray} -x_p(t)&=&\frac{f_0}{2k}+\sum_{n>0} \alpha_n\cos(n\omega t-\delta_n)+\beta_n\sin(n\omega t-\delta_n),\\ -\nonumber -\alpha_n&=&\frac{f_n/m}{\sqrt{((n\omega)^2-\omega_0^2)+4\beta^2n^2\omega^2}},\\ -\nonumber -\beta_n&=&\frac{g_n/m}{\sqrt{((n\omega)^2-\omega_0^2)+4\beta^2n^2\omega^2}},\\ -\nonumber -\delta_n&=&\tan^{-1}\left(\frac{2\beta n\omega}{\omega_0^2-n^2\omega^2}\right). -\end{eqnarray} -$$ - - -









    -

    Finding the Coefficients

    - -

    Because the forces have been applied for a long time, any non-zero -damping eliminates the homogenous parts of the solution, so one need -only consider the particular solution for each \( n \). -

    - -

    The problem is considered solved if one can find expressions for the -coefficients \( f_n \) and \( g_n \), even though the solutions are expressed -as an infinite sum. The coefficients can be extracted from the -function \( F(t) \) by -

    - -$$ -\begin{eqnarray} -\label{eq:fourierdef2} -f_n&=&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~F(t)\cos(2n\pi t/\tau),\\ -\nonumber -g_n&=&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~F(t)\sin(2n\pi t/\tau). -\end{eqnarray} -$$ - -

    To check the consistency of these expressions and to verify -Eq. \eqref{eq:fourierdef2}, one can insert the expansion of \( F(t) \) in -Eq. \eqref{eq:fourierdef1} into the expression for the coefficients in -Eq. \eqref{eq:fourierdef2} and see whether -

    - -$$ -\begin{eqnarray} -f_n&=?&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~\left\{ -\frac{f_0}{2}+\sum_{m>0}f_m\cos(m\omega t)+g_m\sin(m\omega t) -\right\}\cos(n\omega t). -\end{eqnarray} -$$ - -

    Immediately, one can throw away all the terms with \( g_m \) because they -convolute an even and an odd function. The term with \( f_0/2 \) -disappears because \( \cos(n\omega t) \) is equally positive and negative -over the interval and will integrate to zero. For all the terms -\( f_m\cos(m\omega t) \) appearing in the sum, one can use angle addition -formulas to see that \( \cos(m\omega t)\cos(n\omega -t)=(1/2)(\cos[(m+n)\omega t]+\cos[(m-n)\omega t] \). This will integrate -to zero unless \( m=n \). In that case the \( m=n \) term gives -

    - -$$ -\begin{equation} -\int_{-\tau/2}^{\tau/2}dt~\cos^2(m\omega t)=\frac{\tau}{2}, -\label{_auto3} -\end{equation} -$$ - -

    and

    - -$$ -\begin{eqnarray} -f_n&=?&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~f_n/2\\ -\nonumber -&=&f_n~\checkmark. -\end{eqnarray} -$$ - -

    The same method can be used to check for the consistency of \( g_n \).

    - -









    -

    Final words on Fourier Transforms

    - -

    The code here uses the Fourier series applied to a -square wave signal. The code here -visualizes the various approximations given by Fourier series compared -with a square wave with period \( T=0.2 \) (dimensionless time), width \( 0.1 \) and max value of the force \( F=2 \). We -see that when we increase the number of components in the Fourier -series, the Fourier series approximation gets closer and closer to the -square wave signal. -

    - - - -
    -
    -
    -
    -
    -
    import numpy as np
    -import math
    -from scipy import signal
    -import matplotlib.pyplot as plt
    -
    -# number of points                                                                                       
    -n = 500
    -# start and final times                                                                                  
    -t0 = 0.0
    -tn = 1.0
    -# Period                                                                                                 
    -T =0.2
    -# Max value of square signal                                                                             
    -Fmax= 2.0
    -# Width of signal   
    -Width = 0.1
    -t = np.linspace(t0, tn, n, endpoint=False)
    -SqrSignal = np.zeros(n)
    -FourierSeriesSignal = np.zeros(n)
    -SqrSignal = 1.0+signal.square(2*np.pi*5*t+np.pi*Width/T)
    -a0 = Fmax*Width/T
    -FourierSeriesSignal = a0
    -Factor = 2.0*Fmax/np.pi
    -for i in range(1,500):
    -    FourierSeriesSignal += Factor/(i)*np.sin(np.pi*i*Width/T)*np.cos(i*t*2*np.pi/T)
    -plt.plot(t, SqrSignal)
    -plt.plot(t, FourierSeriesSignal)
    -plt.ylim(-0.5, 2.5)
    -plt.show()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -









    Two-dimensional Objects

    @@ -2412,7 +2120,7 @@ samples $$ \begin{equation} x = g(z; \theta^{(g)}) -\label{_auto4} +\label{_auto1} \end{equation} $$ @@ -2429,7 +2137,7 @@ value given by $$ \begin{equation} d(x; \theta^{(d)}) -\label{_auto5} +\label{_auto2} \end{equation} $$ @@ -2442,7 +2150,7 @@ which a function $$ \begin{equation} v(\theta^{(g)}, \theta^{(d)}) -\label{_auto6} +\label{_auto3} \end{equation} $$ @@ -2453,7 +2161,7 @@ conjugate reward $$ \begin{equation} -v(\theta^{(g)}, \theta^{(d)}) -\label{_auto7} +\label{_auto4} \end{equation} $$ @@ -2488,7 +2196,7 @@ $$ \begin{equation} g^* = \underset{g}{\mathrm{argmin}}\hspace{2pt} \underset{d}{\mathrm{max}}v(\theta^{(g)}, \theta^{(d)}) -\label{_auto8} +\label{_auto5} \end{equation} $$ @@ -2498,7 +2206,7 @@ $$ v(\theta^{(g)}, \theta^{(d)}) = \mathbb{E}_{x\sim p_\mathrm{data}}\log d(x) + \mathbb{E}_{x\sim p_\mathrm{model}} \log (1 - d(x)) -\label{_auto9} +\label{_auto6} \end{equation} $$ @@ -2509,7 +2217,7 @@ approximation of a partition function. In the case where $$ \begin{equation} \underset{d}{\mathrm{max}}v(\theta^{(g)}, \theta^{(d)}) -\label{_auto10} +\label{_auto7} \end{equation} $$ diff --git a/doc/pub/week43/html/week43.html b/doc/pub/week43/html/week43.html index 6746ab392..1622adc92 100644 --- a/doc/pub/week43/html/week43.html +++ b/doc/pub/week43/html/week43.html @@ -178,25 +178,6 @@ div.toc p,a { 2, None, 'a-more-efficient-way-of-coding-the-above-convolution'), - ('Convolution Examples: Principle of Superposition and Periodic ' - 'Forces (Fourier Transforms)', - 2, - None, - 'convolution-examples-principle-of-superposition-and-periodic-forces-fourier-transforms'), - ('Principle of Superposition', - 2, - None, - 'principle-of-superposition'), - ('Simple Code Example', 2, None, 'simple-code-example'), - ('Wrapping up Fourier transforms', - 2, - None, - 'wrapping-up-fourier-transforms'), - ('Finding the Coefficients', 2, None, 'finding-the-coefficients'), - ('Final words on Fourier Transforms', - 2, - None, - 'final-words-on-fourier-transforms'), ('Two-dimensional Objects', 2, None, 'two-dimensional-objects'), ('Cross-Correlation', 2, None, 'cross-correlation'), ('More on Dimensionalities', 2, None, 'more-on-dimensionalities'), @@ -324,7 +305,7 @@ MathJax.Hub.Config({
    -

    Oct 26, 2022

    +

    Oct 27, 2022


    @@ -718,279 +699,6 @@ We rather code the convolutions in the minimal memory footprint that they requir

    Does the number of floating point operations change here when we use the commutative property?

    -









    -

    Convolution Examples: Principle of Superposition and Periodic Forces (Fourier Transforms)

    - -

    For problems with so-called harmonic oscillations, given by for example the following differential equation

    -$$ -m\frac{d^2x}{dt^2}+\eta\frac{dx}{dt}+x(t)=F(t), -$$ - -

    where \( F(t) \) is an applied external force acting on the system (often called a driving force), one can use the theory of Fourier transformations to find the solutions of this type of equations.

    - -

    If one has several driving forces, \( F(t)=\sum_n F_n(t) \), one can find -the particular solution to each \( F_n \), \( x_{pn}(t) \), and the particular -solution for the entire driving force is then given by a series like -

    - -$$ -\begin{equation} -x_p(t)=\sum_nx_{pn}(t). -\label{_auto1} -\end{equation} -$$ - - -









    -

    Principle of Superposition

    - -

    This is known as the principle of superposition. It only applies when -the homogenous equation is linear. If there were an anharmonic term -such as \( x^3 \) in the homogenous equation, then when one summed various -solutions, \( x=(\sum_n x_n)^2 \), one would get cross -terms. Superposition is especially useful when \( F(t) \) can be written -as a sum of sinusoidal terms, because the solutions for each -sinusoidal (sine or cosine) term is analytic. -

    - -

    Driving forces are often periodic, even when they are not -sinusoidal. Periodicity implies that for some time \( \tau \) -

    - -$$ -\begin{eqnarray} -F(t+\tau)=F(t). -\end{eqnarray} -$$ - -

    One example of a non-sinusoidal periodic force is a square wave. Many -components in electric circuits are non-linear, e.g. diodes, which -makes many wave forms non-sinusoidal even when the circuits are being -driven by purely sinusoidal sources. -

    - -









    -

    Simple Code Example

    - -

    The code here shows a typical example of such a square wave generated using the functionality included in the scipy Python package. We have used a period of \( \tau=0.2 \).

    - - - -
    -
    -
    -
    -
    -
    import numpy as np
    -import math
    -from scipy import signal
    -import matplotlib.pyplot as plt
    -
    -# number of points                                                                                       
    -n = 500
    -# start and final times                                                                                  
    -t0 = 0.0
    -tn = 1.0
    -# Period                                                                                                 
    -t = np.linspace(t0, tn, n, endpoint=False)
    -SqrSignal = np.zeros(n)
    -SqrSignal = 1.0+signal.square(2*np.pi*5*t)
    -plt.plot(t, SqrSignal)
    -plt.ylim(-0.5, 2.5)
    -plt.show()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    For the sinusoidal example the -period is \( \tau=2\pi/\omega \). However, higher harmonics can also -satisfy the periodicity requirement. In general, any force that -satisfies the periodicity requirement can be expressed as a sum over -harmonics, -

    - -$$ -\begin{equation} -F(t)=\frac{f_0}{2}+\sum_{n>0} f_n\cos(2n\pi t/\tau)+g_n\sin(2n\pi t/\tau). -\label{_auto2} -\end{equation} -$$ - - -









    -

    Wrapping up Fourier transforms

    - -

    We can write down the answer for -\( x_{pn}(t) \), by substituting \( f_n/m \) or \( g_n/m \) for \( F_0/m \). By -writing each factor \( 2n\pi t/\tau \) as \( n\omega t \), with \( \omega\equiv -2\pi/\tau \), -

    - -$$ -\begin{equation} -\label{eq:fourierdef1} -F(t)=\frac{f_0}{2}+\sum_{n>0}f_n\cos(n\omega t)+g_n\sin(n\omega t). -\end{equation} -$$ - -

    The solutions for \( x(t) \) then come from replacing \( \omega \) with -\( n\omega \) for each term in the particular solution, -

    - -$$ -\begin{eqnarray} -x_p(t)&=&\frac{f_0}{2k}+\sum_{n>0} \alpha_n\cos(n\omega t-\delta_n)+\beta_n\sin(n\omega t-\delta_n),\\ -\nonumber -\alpha_n&=&\frac{f_n/m}{\sqrt{((n\omega)^2-\omega_0^2)+4\beta^2n^2\omega^2}},\\ -\nonumber -\beta_n&=&\frac{g_n/m}{\sqrt{((n\omega)^2-\omega_0^2)+4\beta^2n^2\omega^2}},\\ -\nonumber -\delta_n&=&\tan^{-1}\left(\frac{2\beta n\omega}{\omega_0^2-n^2\omega^2}\right). -\end{eqnarray} -$$ - - -









    -

    Finding the Coefficients

    - -

    Because the forces have been applied for a long time, any non-zero -damping eliminates the homogenous parts of the solution, so one need -only consider the particular solution for each \( n \). -

    - -

    The problem is considered solved if one can find expressions for the -coefficients \( f_n \) and \( g_n \), even though the solutions are expressed -as an infinite sum. The coefficients can be extracted from the -function \( F(t) \) by -

    - -$$ -\begin{eqnarray} -\label{eq:fourierdef2} -f_n&=&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~F(t)\cos(2n\pi t/\tau),\\ -\nonumber -g_n&=&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~F(t)\sin(2n\pi t/\tau). -\end{eqnarray} -$$ - -

    To check the consistency of these expressions and to verify -Eq. \eqref{eq:fourierdef2}, one can insert the expansion of \( F(t) \) in -Eq. \eqref{eq:fourierdef1} into the expression for the coefficients in -Eq. \eqref{eq:fourierdef2} and see whether -

    - -$$ -\begin{eqnarray} -f_n&=?&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~\left\{ -\frac{f_0}{2}+\sum_{m>0}f_m\cos(m\omega t)+g_m\sin(m\omega t) -\right\}\cos(n\omega t). -\end{eqnarray} -$$ - -

    Immediately, one can throw away all the terms with \( g_m \) because they -convolute an even and an odd function. The term with \( f_0/2 \) -disappears because \( \cos(n\omega t) \) is equally positive and negative -over the interval and will integrate to zero. For all the terms -\( f_m\cos(m\omega t) \) appearing in the sum, one can use angle addition -formulas to see that \( \cos(m\omega t)\cos(n\omega -t)=(1/2)(\cos[(m+n)\omega t]+\cos[(m-n)\omega t] \). This will integrate -to zero unless \( m=n \). In that case the \( m=n \) term gives -

    - -$$ -\begin{equation} -\int_{-\tau/2}^{\tau/2}dt~\cos^2(m\omega t)=\frac{\tau}{2}, -\label{_auto3} -\end{equation} -$$ - -

    and

    - -$$ -\begin{eqnarray} -f_n&=?&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~f_n/2\\ -\nonumber -&=&f_n~\checkmark. -\end{eqnarray} -$$ - -

    The same method can be used to check for the consistency of \( g_n \).

    - -









    -

    Final words on Fourier Transforms

    - -

    The code here uses the Fourier series applied to a -square wave signal. The code here -visualizes the various approximations given by Fourier series compared -with a square wave with period \( T=0.2 \) (dimensionless time), width \( 0.1 \) and max value of the force \( F=2 \). We -see that when we increase the number of components in the Fourier -series, the Fourier series approximation gets closer and closer to the -square wave signal. -

    - - - -
    -
    -
    -
    -
    -
    import numpy as np
    -import math
    -from scipy import signal
    -import matplotlib.pyplot as plt
    -
    -# number of points                                                                                       
    -n = 500
    -# start and final times                                                                                  
    -t0 = 0.0
    -tn = 1.0
    -# Period                                                                                                 
    -T =0.2
    -# Max value of square signal                                                                             
    -Fmax= 2.0
    -# Width of signal   
    -Width = 0.1
    -t = np.linspace(t0, tn, n, endpoint=False)
    -SqrSignal = np.zeros(n)
    -FourierSeriesSignal = np.zeros(n)
    -SqrSignal = 1.0+signal.square(2*np.pi*5*t+np.pi*Width/T)
    -a0 = Fmax*Width/T
    -FourierSeriesSignal = a0
    -Factor = 2.0*Fmax/np.pi
    -for i in range(1,500):
    -    FourierSeriesSignal += Factor/(i)*np.sin(np.pi*i*Width/T)*np.cos(i*t*2*np.pi/T)
    -plt.plot(t, SqrSignal)
    -plt.plot(t, FourierSeriesSignal)
    -plt.ylim(-0.5, 2.5)
    -plt.show()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -









    Two-dimensional Objects

    @@ -2489,7 +2197,7 @@ samples $$ \begin{equation} x = g(z; \theta^{(g)}) -\label{_auto4} +\label{_auto1} \end{equation} $$ @@ -2506,7 +2214,7 @@ value given by $$ \begin{equation} d(x; \theta^{(d)}) -\label{_auto5} +\label{_auto2} \end{equation} $$ @@ -2519,7 +2227,7 @@ which a function $$ \begin{equation} v(\theta^{(g)}, \theta^{(d)}) -\label{_auto6} +\label{_auto3} \end{equation} $$ @@ -2530,7 +2238,7 @@ conjugate reward $$ \begin{equation} -v(\theta^{(g)}, \theta^{(d)}) -\label{_auto7} +\label{_auto4} \end{equation} $$ @@ -2565,7 +2273,7 @@ $$ \begin{equation} g^* = \underset{g}{\mathrm{argmin}}\hspace{2pt} \underset{d}{\mathrm{max}}v(\theta^{(g)}, \theta^{(d)}) -\label{_auto8} +\label{_auto5} \end{equation} $$ @@ -2575,7 +2283,7 @@ $$ v(\theta^{(g)}, \theta^{(d)}) = \mathbb{E}_{x\sim p_\mathrm{data}}\log d(x) + \mathbb{E}_{x\sim p_\mathrm{model}} \log (1 - d(x)) -\label{_auto9} +\label{_auto6} \end{equation} $$ @@ -2586,7 +2294,7 @@ approximation of a partition function. In the case where $$ \begin{equation} \underset{d}{\mathrm{max}}v(\theta^{(g)}, \theta^{(d)}) -\label{_auto10} +\label{_auto7} \end{equation} $$ diff --git a/doc/pub/week43/ipynb/ipynb-week43-src.tar.gz b/doc/pub/week43/ipynb/ipynb-week43-src.tar.gz index 3b74eee4739bedc8a407369a47b1bf77e690203c..70ac235d0534ae10f22a5da779ca7d7f6f6e03ff 100644 GIT binary patch delta 21 ccmbQbfpzKzR(APr4u;K)QH|_d*%|pF08AAI2LJ#7 delta 21 dcmbQbfpzKzR(APr4u-?qA{yDZvNQ5U002`02Fd^c diff --git a/doc/pub/week43/ipynb/week43.ipynb b/doc/pub/week43/ipynb/week43.ipynb index ede095fd8..20be67035 100644 --- a/doc/pub/week43/ipynb/week43.ipynb +++ b/doc/pub/week43/ipynb/week43.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "f0ce1e7c", + "id": "39b8be43", "metadata": { "editable": true }, @@ -14,7 +14,7 @@ }, { "cell_type": "markdown", - "id": "69bc93ec", + "id": "981f16fe", "metadata": { "editable": true }, @@ -22,14 +22,14 @@ "# Week 43: Deep Learning: Convolutional Neural Networks and Recurrent Neural Networks\n", "**Morten Hjorth-Jensen**, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University\n", "\n", - "Date: **Oct 26, 2022**\n", + "Date: **Oct 27, 2022**\n", "\n", "Copyright 1999-2022, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license" ] }, { "cell_type": "markdown", - "id": "ae8a30ae", + "id": "7aca1639", "metadata": { "editable": true }, @@ -57,7 +57,7 @@ }, { "cell_type": "markdown", - "id": "cb384145", + "id": "0738d710", "metadata": { "editable": true }, @@ -83,7 +83,7 @@ }, { "cell_type": "markdown", - "id": "74864f8b", + "id": "a89b65f5", "metadata": { "editable": true }, @@ -110,7 +110,7 @@ }, { "cell_type": "markdown", - "id": "d0224956", + "id": "b9fec0a0", "metadata": { "editable": true }, @@ -132,7 +132,7 @@ }, { "cell_type": "markdown", - "id": "e336b07e", + "id": "7b3a72f4", "metadata": { "editable": true }, @@ -150,7 +150,7 @@ }, { "cell_type": "markdown", - "id": "72c1f940", + "id": "729acf66", "metadata": { "editable": true }, @@ -180,7 +180,7 @@ }, { "cell_type": "markdown", - "id": "492c2968", + "id": "fdfcbaca", "metadata": { "editable": true }, @@ -210,7 +210,7 @@ }, { "cell_type": "markdown", - "id": "00c32fbf", + "id": "9f7d0f80", "metadata": { "editable": true }, @@ -250,7 +250,7 @@ }, { "cell_type": "markdown", - "id": "9ebd6d86", + "id": "cfe305fd", "metadata": { "editable": true }, @@ -279,7 +279,7 @@ }, { "cell_type": "markdown", - "id": "f6ed4eae", + "id": "835b3d02", "metadata": { "editable": true }, @@ -301,7 +301,7 @@ }, { "cell_type": "markdown", - "id": "82ea9bb8", + "id": "3ed900c8", "metadata": { "editable": true }, @@ -330,7 +330,7 @@ }, { "cell_type": "markdown", - "id": "54748a1c", + "id": "a114da8c", "metadata": { "editable": true }, @@ -347,7 +347,7 @@ }, { "cell_type": "markdown", - "id": "a276a5f7", + "id": "9f71e171", "metadata": { "editable": true }, @@ -367,7 +367,7 @@ }, { "cell_type": "markdown", - "id": "621472ec", + "id": "d180a2df", "metadata": { "editable": true }, @@ -379,7 +379,7 @@ }, { "cell_type": "markdown", - "id": "36ad9fcf", + "id": "cbc3240d", "metadata": { "editable": true }, @@ -391,7 +391,7 @@ }, { "cell_type": "markdown", - "id": "f96e464e", + "id": "d70004e9", "metadata": { "editable": true }, @@ -403,7 +403,7 @@ }, { "cell_type": "markdown", - "id": "b5f2d604", + "id": "78381319", "metadata": { "editable": true }, @@ -413,7 +413,7 @@ }, { "cell_type": "markdown", - "id": "4c741612", + "id": "ba664a73", "metadata": { "editable": true }, @@ -425,7 +425,7 @@ }, { "cell_type": "markdown", - "id": "cf1b0a1d", + "id": "9426138c", "metadata": { "editable": true }, @@ -437,7 +437,7 @@ }, { "cell_type": "markdown", - "id": "648821f2", + "id": "a656bb9b", "metadata": { "editable": true }, @@ -452,7 +452,7 @@ }, { "cell_type": "markdown", - "id": "06c22baa", + "id": "50f5a4ab", "metadata": { "editable": true }, @@ -464,7 +464,7 @@ }, { "cell_type": "markdown", - "id": "57610ce1", + "id": "17de3697", "metadata": { "editable": true }, @@ -474,7 +474,7 @@ }, { "cell_type": "markdown", - "id": "a7886eed", + "id": "17fab12e", "metadata": { "editable": true }, @@ -486,7 +486,7 @@ }, { "cell_type": "markdown", - "id": "a5b9a2c2", + "id": "0fc7fdfc", "metadata": { "editable": true }, @@ -496,7 +496,7 @@ }, { "cell_type": "markdown", - "id": "05b529f3", + "id": "134a8756", "metadata": { "editable": true }, @@ -508,7 +508,7 @@ }, { "cell_type": "markdown", - "id": "ecc371e8", + "id": "49f18583", "metadata": { "editable": true }, @@ -521,7 +521,7 @@ }, { "cell_type": "markdown", - "id": "30ccb0ac", + "id": "0a133131", "metadata": { "editable": true }, @@ -540,7 +540,7 @@ }, { "cell_type": "markdown", - "id": "3e2b21d1", + "id": "87dddd49", "metadata": { "editable": true }, @@ -552,7 +552,7 @@ }, { "cell_type": "markdown", - "id": "8cebfaa8", + "id": "3f6e119e", "metadata": { "editable": true }, @@ -564,7 +564,7 @@ }, { "cell_type": "markdown", - "id": "23165deb", + "id": "56e30dfe", "metadata": { "editable": true }, @@ -574,7 +574,7 @@ }, { "cell_type": "markdown", - "id": "67d68ec1", + "id": "d0f110c8", "metadata": { "editable": true }, @@ -586,7 +586,7 @@ }, { "cell_type": "markdown", - "id": "4b96c4e8", + "id": "8546e9d2", "metadata": { "editable": true }, @@ -596,7 +596,7 @@ }, { "cell_type": "markdown", - "id": "a4d77b6b", + "id": "d0cd0cd6", "metadata": { "editable": true }, @@ -610,7 +610,7 @@ }, { "cell_type": "markdown", - "id": "d9daeca5", + "id": "5bf16241", "metadata": { "editable": true }, @@ -628,7 +628,7 @@ }, { "cell_type": "markdown", - "id": "9e6a7654", + "id": "3d725759", "metadata": { "editable": true }, @@ -639,7 +639,7 @@ }, { "cell_type": "markdown", - "id": "961cc256", + "id": "20dfc827", "metadata": { "editable": true }, @@ -657,7 +657,7 @@ }, { "cell_type": "markdown", - "id": "50f98c11", + "id": "d0252d98", "metadata": { "editable": true }, @@ -671,448 +671,7 @@ }, { "cell_type": "markdown", - "id": "423e695e", - "metadata": { - "editable": true - }, - "source": [ - "## Convolution Examples: Principle of Superposition and Periodic Forces (Fourier Transforms)\n", - "\n", - "For problems with so-called harmonic oscillations, given by for example the following differential equation" - ] - }, - { - "cell_type": "markdown", - "id": "2c73001b", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "m\\frac{d^2x}{dt^2}+\\eta\\frac{dx}{dt}+x(t)=F(t),\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "31a9f132", - "metadata": { - "editable": true - }, - "source": [ - "where $F(t)$ is an applied external force acting on the system (often called a driving force), one can use the theory of Fourier transformations to find the solutions of this type of equations.\n", - "\n", - "If one has several driving forces, $F(t)=\\sum_n F_n(t)$, one can find\n", - "the particular solution to each $F_n$, $x_{pn}(t)$, and the particular\n", - "solution for the entire driving force is then given by a series like" - ] - }, - { - "cell_type": "markdown", - "id": "00a3d7fd", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
    \n", - "\n", - "$$\n", - "\\begin{equation}\n", - "x_p(t)=\\sum_nx_{pn}(t).\n", - "\\label{_auto1} \\tag{1}\n", - "\\end{equation}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "d97d3ada", - "metadata": { - "editable": true - }, - "source": [ - "## Principle of Superposition\n", - "\n", - "This is known as the principle of superposition. It only applies when\n", - "the homogenous equation is linear. If there were an anharmonic term\n", - "such as $x^3$ in the homogenous equation, then when one summed various\n", - "solutions, $x=(\\sum_n x_n)^2$, one would get cross\n", - "terms. Superposition is especially useful when $F(t)$ can be written\n", - "as a sum of sinusoidal terms, because the solutions for each\n", - "sinusoidal (sine or cosine) term is analytic. \n", - "\n", - "Driving forces are often periodic, even when they are not\n", - "sinusoidal. Periodicity implies that for some time $\\tau$" - ] - }, - { - "cell_type": "markdown", - "id": "43e0d286", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\begin{eqnarray}\n", - "F(t+\\tau)=F(t). \n", - "\\end{eqnarray}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "b0ab9ed9", - "metadata": { - "editable": true - }, - "source": [ - "One example of a non-sinusoidal periodic force is a square wave. Many\n", - "components in electric circuits are non-linear, e.g. diodes, which\n", - "makes many wave forms non-sinusoidal even when the circuits are being\n", - "driven by purely sinusoidal sources." - ] - }, - { - "cell_type": "markdown", - "id": "b66bf960", - "metadata": { - "editable": true - }, - "source": [ - "## Simple Code Example\n", - "\n", - "The code here shows a typical example of such a square wave generated using the functionality included in the **scipy** Python package. We have used a period of $\\tau=0.2$." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "1bbe3483", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [], - "source": [ - "%matplotlib inline\n", - "\n", - "import numpy as np\n", - "import math\n", - "from scipy import signal\n", - "import matplotlib.pyplot as plt\n", - "\n", - "# number of points \n", - "n = 500\n", - "# start and final times \n", - "t0 = 0.0\n", - "tn = 1.0\n", - "# Period \n", - "t = np.linspace(t0, tn, n, endpoint=False)\n", - "SqrSignal = np.zeros(n)\n", - "SqrSignal = 1.0+signal.square(2*np.pi*5*t)\n", - "plt.plot(t, SqrSignal)\n", - "plt.ylim(-0.5, 2.5)\n", - "plt.show()" - ] - }, - { - "cell_type": "markdown", - "id": "a3052caf", - "metadata": { - "editable": true - }, - "source": [ - "For the sinusoidal example the\n", - "period is $\\tau=2\\pi/\\omega$. However, higher harmonics can also\n", - "satisfy the periodicity requirement. In general, any force that\n", - "satisfies the periodicity requirement can be expressed as a sum over\n", - "harmonics," - ] - }, - { - "cell_type": "markdown", - "id": "6afff4d2", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
    \n", - "\n", - "$$\n", - "\\begin{equation}\n", - "F(t)=\\frac{f_0}{2}+\\sum_{n>0} f_n\\cos(2n\\pi t/\\tau)+g_n\\sin(2n\\pi t/\\tau).\n", - "\\label{_auto2} \\tag{2}\n", - "\\end{equation}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "cc740c35", - "metadata": { - "editable": true - }, - "source": [ - "## Wrapping up Fourier transforms\n", - "\n", - "We can write down the answer for\n", - "$x_{pn}(t)$, by substituting $f_n/m$ or $g_n/m$ for $F_0/m$. By\n", - "writing each factor $2n\\pi t/\\tau$ as $n\\omega t$, with $\\omega\\equiv\n", - "2\\pi/\\tau$," - ] - }, - { - "cell_type": "markdown", - "id": "14481252", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
    \n", - "\n", - "$$\n", - "\\begin{equation}\n", - "\\label{eq:fourierdef1} \\tag{3}\n", - "F(t)=\\frac{f_0}{2}+\\sum_{n>0}f_n\\cos(n\\omega t)+g_n\\sin(n\\omega t).\n", - "\\end{equation}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "4b848c46", - "metadata": { - "editable": true - }, - "source": [ - "The solutions for $x(t)$ then come from replacing $\\omega$ with\n", - "$n\\omega$ for each term in the particular solution," - ] - }, - { - "cell_type": "markdown", - "id": "69e949a7", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\begin{eqnarray}\n", - "x_p(t)&=&\\frac{f_0}{2k}+\\sum_{n>0} \\alpha_n\\cos(n\\omega t-\\delta_n)+\\beta_n\\sin(n\\omega t-\\delta_n),\\\\\n", - "\\nonumber\n", - "\\alpha_n&=&\\frac{f_n/m}{\\sqrt{((n\\omega)^2-\\omega_0^2)+4\\beta^2n^2\\omega^2}},\\\\\n", - "\\nonumber\n", - "\\beta_n&=&\\frac{g_n/m}{\\sqrt{((n\\omega)^2-\\omega_0^2)+4\\beta^2n^2\\omega^2}},\\\\\n", - "\\nonumber\n", - "\\delta_n&=&\\tan^{-1}\\left(\\frac{2\\beta n\\omega}{\\omega_0^2-n^2\\omega^2}\\right).\n", - "\\end{eqnarray}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "d31fca57", - "metadata": { - "editable": true - }, - "source": [ - "## Finding the Coefficients\n", - "\n", - "Because the forces have been applied for a long time, any non-zero\n", - "damping eliminates the homogenous parts of the solution, so one need\n", - "only consider the particular solution for each $n$.\n", - "\n", - "The problem is considered solved if one can find expressions for the\n", - "coefficients $f_n$ and $g_n$, even though the solutions are expressed\n", - "as an infinite sum. The coefficients can be extracted from the\n", - "function $F(t)$ by" - ] - }, - { - "cell_type": "markdown", - "id": "a0d059f0", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
    \n", - "\n", - "$$\n", - "\\begin{eqnarray}\n", - "\\label{eq:fourierdef2} \\tag{4}\n", - "f_n&=&\\frac{2}{\\tau}\\int_{-\\tau/2}^{\\tau/2} dt~F(t)\\cos(2n\\pi t/\\tau),\\\\\n", - "\\nonumber\n", - "g_n&=&\\frac{2}{\\tau}\\int_{-\\tau/2}^{\\tau/2} dt~F(t)\\sin(2n\\pi t/\\tau).\n", - "\\end{eqnarray}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "ec0780f8", - "metadata": { - "editable": true - }, - "source": [ - "To check the consistency of these expressions and to verify\n", - "Eq. ([4](#eq:fourierdef2)), one can insert the expansion of $F(t)$ in\n", - "Eq. ([3](#eq:fourierdef1)) into the expression for the coefficients in\n", - "Eq. ([4](#eq:fourierdef2)) and see whether" - ] - }, - { - "cell_type": "markdown", - "id": "50f9ce17", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\begin{eqnarray}\n", - "f_n&=?&\\frac{2}{\\tau}\\int_{-\\tau/2}^{\\tau/2} dt~\\left\\{\n", - "\\frac{f_0}{2}+\\sum_{m>0}f_m\\cos(m\\omega t)+g_m\\sin(m\\omega t)\n", - "\\right\\}\\cos(n\\omega t).\n", - "\\end{eqnarray}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "7e9e750b", - "metadata": { - "editable": true - }, - "source": [ - "Immediately, one can throw away all the terms with $g_m$ because they\n", - "convolute an even and an odd function. The term with $f_0/2$\n", - "disappears because $\\cos(n\\omega t)$ is equally positive and negative\n", - "over the interval and will integrate to zero. For all the terms\n", - "$f_m\\cos(m\\omega t)$ appearing in the sum, one can use angle addition\n", - "formulas to see that $\\cos(m\\omega t)\\cos(n\\omega\n", - "t)=(1/2)(\\cos[(m+n)\\omega t]+\\cos[(m-n)\\omega t]$. This will integrate\n", - "to zero unless $m=n$. In that case the $m=n$ term gives" - ] - }, - { - "cell_type": "markdown", - "id": "9bbd9a43", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
    \n", - "\n", - "$$\n", - "\\begin{equation}\n", - "\\int_{-\\tau/2}^{\\tau/2}dt~\\cos^2(m\\omega t)=\\frac{\\tau}{2},\n", - "\\label{_auto3} \\tag{5}\n", - "\\end{equation}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "5e0f715a", - "metadata": { - "editable": true - }, - "source": [ - "and" - ] - }, - { - "cell_type": "markdown", - "id": "e43d4499", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\begin{eqnarray}\n", - "f_n&=?&\\frac{2}{\\tau}\\int_{-\\tau/2}^{\\tau/2} dt~f_n/2\\\\\n", - "\\nonumber\n", - "&=&f_n~\\checkmark.\n", - "\\end{eqnarray}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "448fdf46", - "metadata": { - "editable": true - }, - "source": [ - "The same method can be used to check for the consistency of $g_n$." - ] - }, - { - "cell_type": "markdown", - "id": "0f1cae03", - "metadata": { - "editable": true - }, - "source": [ - "## Final words on Fourier Transforms\n", - "\n", - "The code here uses the Fourier series applied to a \n", - "square wave signal. The code here\n", - "visualizes the various approximations given by Fourier series compared\n", - "with a square wave with period $T=0.2$ (dimensionless time), width $0.1$ and max value of the force $F=2$. We\n", - "see that when we increase the number of components in the Fourier\n", - "series, the Fourier series approximation gets closer and closer to the\n", - "square wave signal." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "9a743c7e", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [], - "source": [ - "import numpy as np\n", - "import math\n", - "from scipy import signal\n", - "import matplotlib.pyplot as plt\n", - "\n", - "# number of points \n", - "n = 500\n", - "# start and final times \n", - "t0 = 0.0\n", - "tn = 1.0\n", - "# Period \n", - "T =0.2\n", - "# Max value of square signal \n", - "Fmax= 2.0\n", - "# Width of signal \n", - "Width = 0.1\n", - "t = np.linspace(t0, tn, n, endpoint=False)\n", - "SqrSignal = np.zeros(n)\n", - "FourierSeriesSignal = np.zeros(n)\n", - "SqrSignal = 1.0+signal.square(2*np.pi*5*t+np.pi*Width/T)\n", - "a0 = Fmax*Width/T\n", - "FourierSeriesSignal = a0\n", - "Factor = 2.0*Fmax/np.pi\n", - "for i in range(1,500):\n", - " FourierSeriesSignal += Factor/(i)*np.sin(np.pi*i*Width/T)*np.cos(i*t*2*np.pi/T)\n", - "plt.plot(t, SqrSignal)\n", - "plt.plot(t, FourierSeriesSignal)\n", - "plt.ylim(-0.5, 2.5)\n", - "plt.show()" - ] - }, - { - "cell_type": "markdown", - "id": "f05ebf25", + "id": "ab474876", "metadata": { "editable": true }, @@ -1126,7 +685,7 @@ }, { "cell_type": "markdown", - "id": "b934e71a", + "id": "c7f5d0fa", "metadata": { "editable": true }, @@ -1138,7 +697,7 @@ }, { "cell_type": "markdown", - "id": "d4198f5a", + "id": "4b5fb733", "metadata": { "editable": true }, @@ -1148,7 +707,7 @@ }, { "cell_type": "markdown", - "id": "c859b325", + "id": "2c5ee11a", "metadata": { "editable": true }, @@ -1160,7 +719,7 @@ }, { "cell_type": "markdown", - "id": "bf8ae95d", + "id": "f3826915", "metadata": { "editable": true }, @@ -1170,7 +729,7 @@ }, { "cell_type": "markdown", - "id": "6bb30331", + "id": "c269d422", "metadata": { "editable": true }, @@ -1182,7 +741,7 @@ }, { "cell_type": "markdown", - "id": "e9ec179a", + "id": "ba66369a", "metadata": { "editable": true }, @@ -1194,7 +753,7 @@ }, { "cell_type": "markdown", - "id": "dcddb36c", + "id": "d77df352", "metadata": { "editable": true }, @@ -1221,7 +780,7 @@ }, { "cell_type": "markdown", - "id": "2e26483e", + "id": "f0ed0734", "metadata": { "editable": true }, @@ -1233,7 +792,7 @@ }, { "cell_type": "markdown", - "id": "488b9e9f", + "id": "6f55f182", "metadata": { "editable": true }, @@ -1243,7 +802,7 @@ }, { "cell_type": "markdown", - "id": "d4a6e4e2", + "id": "43a71ede", "metadata": { "editable": true }, @@ -1269,7 +828,7 @@ }, { "cell_type": "markdown", - "id": "30f07dd9", + "id": "2c837269", "metadata": { "editable": true }, @@ -1281,7 +840,7 @@ }, { "cell_type": "markdown", - "id": "513b3c6e", + "id": "2a9ad7b9", "metadata": { "editable": true }, @@ -1300,7 +859,7 @@ }, { "cell_type": "markdown", - "id": "9003ad9d", + "id": "0e5b2fda", "metadata": { "editable": true }, @@ -1313,7 +872,7 @@ }, { "cell_type": "markdown", - "id": "32125ddf", + "id": "0941946b", "metadata": { "editable": true }, @@ -1325,7 +884,7 @@ }, { "cell_type": "markdown", - "id": "1e9d4aa7", + "id": "003a1566", "metadata": { "editable": true }, @@ -1346,7 +905,7 @@ }, { "cell_type": "markdown", - "id": "4ce70b16", + "id": "87d1f1ca", "metadata": { "editable": true }, @@ -1367,7 +926,7 @@ }, { "cell_type": "markdown", - "id": "f9bbb418", + "id": "30b06d7d", "metadata": { "editable": true }, @@ -1392,7 +951,7 @@ }, { "cell_type": "markdown", - "id": "a277b22c", + "id": "743f06a8", "metadata": { "editable": true }, @@ -1411,7 +970,7 @@ }, { "cell_type": "markdown", - "id": "9f7e96f6", + "id": "d59f6dc7", "metadata": { "editable": true }, @@ -1421,14 +980,16 @@ }, { "cell_type": "code", - "execution_count": 3, - "id": "90dbcb4c", + "execution_count": 1, + "id": "417c5313", "metadata": { "collapsed": false, "editable": true }, "outputs": [], "source": [ + "%matplotlib inline\n", + "\n", "# import necessary packages\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", @@ -1473,7 +1034,7 @@ }, { "cell_type": "markdown", - "id": "f7c5c8fa", + "id": "7ccf748d", "metadata": { "editable": true }, @@ -1483,8 +1044,8 @@ }, { "cell_type": "code", - "execution_count": 4, - "id": "a781ec9d", + "execution_count": 2, + "id": "82799ffb", "metadata": { "collapsed": false, "editable": true @@ -1517,7 +1078,7 @@ }, { "cell_type": "markdown", - "id": "b24dce93", + "id": "3e1314e2", "metadata": { "editable": true }, @@ -1527,8 +1088,8 @@ }, { "cell_type": "code", - "execution_count": 5, - "id": "9fc568f6", + "execution_count": 3, + "id": "78c6d776", "metadata": { "collapsed": false, "editable": true @@ -1565,7 +1126,7 @@ }, { "cell_type": "markdown", - "id": "e1ab86b1", + "id": "e4214e05", "metadata": { "editable": true }, @@ -1575,8 +1136,8 @@ }, { "cell_type": "code", - "execution_count": 6, - "id": "992c7388", + "execution_count": 4, + "id": "10588ba5", "metadata": { "collapsed": false, "editable": true @@ -1603,7 +1164,7 @@ }, { "cell_type": "markdown", - "id": "c00c71cb", + "id": "25d5b166", "metadata": { "editable": true }, @@ -1613,8 +1174,8 @@ }, { "cell_type": "code", - "execution_count": 7, - "id": "e7da96ed", + "execution_count": 5, + "id": "53c4c070", "metadata": { "collapsed": false, "editable": true @@ -1655,7 +1216,7 @@ }, { "cell_type": "markdown", - "id": "50918927", + "id": "089137f3", "metadata": { "editable": true }, @@ -1670,8 +1231,8 @@ }, { "cell_type": "code", - "execution_count": 8, - "id": "675ff929", + "execution_count": 6, + "id": "2cb784c5", "metadata": { "collapsed": false, "editable": true @@ -1692,7 +1253,7 @@ }, { "cell_type": "markdown", - "id": "86f3c8b3", + "id": "14f28852", "metadata": { "editable": true }, @@ -1704,8 +1265,8 @@ }, { "cell_type": "code", - "execution_count": 9, - "id": "ab94b3dc", + "execution_count": 7, + "id": "0ba4ca13", "metadata": { "collapsed": false, "editable": true @@ -1730,7 +1291,7 @@ }, { "cell_type": "markdown", - "id": "9d0aefcb", + "id": "4028926b", "metadata": { "editable": true }, @@ -1744,8 +1305,8 @@ }, { "cell_type": "code", - "execution_count": 10, - "id": "b940c223", + "execution_count": 8, + "id": "77305c3a", "metadata": { "collapsed": false, "editable": true @@ -1766,7 +1327,7 @@ }, { "cell_type": "markdown", - "id": "94968eef", + "id": "5ec8e536", "metadata": { "editable": true }, @@ -1776,7 +1337,7 @@ }, { "cell_type": "markdown", - "id": "fcab6714", + "id": "e1d080b0", "metadata": { "editable": true }, @@ -1794,8 +1355,8 @@ }, { "cell_type": "code", - "execution_count": 11, - "id": "a6b8c6c9", + "execution_count": 9, + "id": "3e422c76", "metadata": { "collapsed": false, "editable": true @@ -1812,7 +1373,7 @@ }, { "cell_type": "markdown", - "id": "20812f49", + "id": "f9a36b78", "metadata": { "editable": true }, @@ -1822,7 +1383,7 @@ }, { "cell_type": "markdown", - "id": "ea439231", + "id": "b87c6227", "metadata": { "editable": true }, @@ -1832,8 +1393,8 @@ }, { "cell_type": "code", - "execution_count": 12, - "id": "c89e998e", + "execution_count": 10, + "id": "c8daa6c0", "metadata": { "collapsed": false, "editable": true @@ -1850,7 +1411,7 @@ }, { "cell_type": "markdown", - "id": "f5f2c190", + "id": "7c26a962", "metadata": { "editable": true }, @@ -1860,8 +1421,8 @@ }, { "cell_type": "code", - "execution_count": 13, - "id": "076273ff", + "execution_count": 11, + "id": "9ec81857", "metadata": { "collapsed": false, "editable": true @@ -1882,7 +1443,7 @@ }, { "cell_type": "markdown", - "id": "2b008ba7", + "id": "1b3226d3", "metadata": { "editable": true }, @@ -1909,7 +1470,7 @@ }, { "cell_type": "markdown", - "id": "3dbf16ac", + "id": "f28aec4c", "metadata": { "editable": true }, @@ -1921,7 +1482,7 @@ }, { "cell_type": "markdown", - "id": "e331daed", + "id": "96bedeb0", "metadata": { "editable": true }, @@ -1931,8 +1492,8 @@ }, { "cell_type": "code", - "execution_count": 14, - "id": "7f4d3a02", + "execution_count": 12, + "id": "15054b4c", "metadata": { "collapsed": false, "editable": true @@ -2011,7 +1572,7 @@ }, { "cell_type": "markdown", - "id": "11dbe758", + "id": "47fb0a0f", "metadata": { "editable": true }, @@ -2026,8 +1587,8 @@ }, { "cell_type": "code", - "execution_count": 15, - "id": "8e877c4a", + "execution_count": 13, + "id": "3dc1bfac", "metadata": { "collapsed": false, "editable": true @@ -2066,7 +1627,7 @@ }, { "cell_type": "markdown", - "id": "008e976a", + "id": "08467731", "metadata": { "editable": true }, @@ -2109,8 +1670,8 @@ }, { "cell_type": "code", - "execution_count": 16, - "id": "9fbab9f9", + "execution_count": 14, + "id": "9a790c4a", "metadata": { "collapsed": false, "editable": true @@ -2193,7 +1754,7 @@ }, { "cell_type": "markdown", - "id": "a96794a9", + "id": "4944b904", "metadata": { "editable": true }, @@ -2203,8 +1764,8 @@ }, { "cell_type": "code", - "execution_count": 17, - "id": "cfe068fe", + "execution_count": 15, + "id": "4cb04f33", "metadata": { "collapsed": false, "editable": true @@ -2306,7 +1867,7 @@ }, { "cell_type": "markdown", - "id": "ea9e0322", + "id": "634efe9e", "metadata": { "editable": true }, @@ -2327,8 +1888,8 @@ }, { "cell_type": "code", - "execution_count": 18, - "id": "d05f5ffd", + "execution_count": 16, + "id": "f9ef7993", "metadata": { "collapsed": false, "editable": true @@ -2425,7 +1986,7 @@ }, { "cell_type": "markdown", - "id": "d58c3996", + "id": "79a4f19e", "metadata": { "editable": true }, @@ -2450,8 +2011,8 @@ }, { "cell_type": "code", - "execution_count": 19, - "id": "5fa1ac19", + "execution_count": 17, + "id": "b17e5462", "metadata": { "collapsed": false, "editable": true @@ -2652,7 +2213,7 @@ }, { "cell_type": "markdown", - "id": "db76936f", + "id": "a7132fba", "metadata": { "editable": true }, @@ -2676,7 +2237,7 @@ }, { "cell_type": "markdown", - "id": "59ac0a32", + "id": "f9df1cc8", "metadata": { "editable": true }, @@ -2696,25 +2257,25 @@ }, { "cell_type": "markdown", - "id": "5a040884", + "id": "12e40216", "metadata": { "editable": true }, "source": [ "\n", - "
    \n", + "
    \n", "\n", "$$\n", "\\begin{equation}\n", " x = g(z; \\theta^{(g)})\n", - "\\label{_auto4} \\tag{6}\n", + "\\label{_auto1} \\tag{1}\n", "\\end{equation}\n", "$$" ] }, { "cell_type": "markdown", - "id": "d094c96e", + "id": "8f12901e", "metadata": { "editable": true }, @@ -2729,25 +2290,25 @@ }, { "cell_type": "markdown", - "id": "fedff397", + "id": "af9857c3", "metadata": { "editable": true }, "source": [ "\n", - "
    \n", + "
    \n", "\n", "$$\n", "\\begin{equation}\n", " d(x; \\theta^{(d)})\n", - "\\label{_auto5} \\tag{7}\n", + "\\label{_auto2} \\tag{2}\n", "\\end{equation}\n", "$$" ] }, { "cell_type": "markdown", - "id": "7b27cf12", + "id": "a71ba9e0", "metadata": { "editable": true }, @@ -2760,25 +2321,25 @@ }, { "cell_type": "markdown", - "id": "3e57f8cf", + "id": "81c84ba1", "metadata": { "editable": true }, "source": [ "\n", - "
    \n", + "
    \n", "\n", "$$\n", "\\begin{equation}\n", " v(\\theta^{(g)}, \\theta^{(d)})\n", - "\\label{_auto6} \\tag{8}\n", + "\\label{_auto3} \\tag{3}\n", "\\end{equation}\n", "$$" ] }, { "cell_type": "markdown", - "id": "b7c9f56c", + "id": "d980ae45", "metadata": { "editable": true }, @@ -2789,25 +2350,25 @@ }, { "cell_type": "markdown", - "id": "030b9916", + "id": "081c310d", "metadata": { "editable": true }, "source": [ "\n", - "
    \n", + "
    \n", "\n", "$$\n", "\\begin{equation}\n", " -v(\\theta^{(g)}, \\theta^{(d)})\n", - "\\label{_auto7} \\tag{9}\n", + "\\label{_auto4} \\tag{4}\n", "\\end{equation}\n", "$$" ] }, { "cell_type": "markdown", - "id": "a738b0b9", + "id": "c887753e", "metadata": { "editable": true }, @@ -2834,7 +2395,7 @@ }, { "cell_type": "markdown", - "id": "89db70a6", + "id": "fd23b374", "metadata": { "editable": true }, @@ -2846,26 +2407,26 @@ }, { "cell_type": "markdown", - "id": "dec4da11", + "id": "a42749ed", "metadata": { "editable": true }, "source": [ "\n", - "
    \n", + "
    \n", "\n", "$$\n", "\\begin{equation}\n", " g^* = \\underset{g}{\\mathrm{argmin}}\\hspace{2pt}\n", " \\underset{d}{\\mathrm{max}}v(\\theta^{(g)}, \\theta^{(d)})\n", - "\\label{_auto8} \\tag{10}\n", + "\\label{_auto5} \\tag{5}\n", "\\end{equation}\n", "$$" ] }, { "cell_type": "markdown", - "id": "ae083a73", + "id": "f0bbd801", "metadata": { "editable": true }, @@ -2875,27 +2436,27 @@ }, { "cell_type": "markdown", - "id": "b1628e82", + "id": "2fc9575e", "metadata": { "editable": true }, "source": [ "\n", - "
    \n", + "
    \n", "\n", "$$\n", "\\begin{equation}\n", " v(\\theta^{(g)}, \\theta^{(d)}) = \\mathbb{E}_{x\\sim p_\\mathrm{data}}\\log d(x)\n", " + \\mathbb{E}_{x\\sim p_\\mathrm{model}}\n", " \\log (1 - d(x))\n", - "\\label{_auto9} \\tag{11}\n", + "\\label{_auto6} \\tag{6}\n", "\\end{equation}\n", "$$" ] }, { "cell_type": "markdown", - "id": "a0c91823", + "id": "3b3e0076", "metadata": { "editable": true }, @@ -2907,25 +2468,25 @@ }, { "cell_type": "markdown", - "id": "2630f04f", + "id": "26765939", "metadata": { "editable": true }, "source": [ "\n", - "
    \n", + "
    \n", "\n", "$$\n", "\\begin{equation}\n", " \\underset{d}{\\mathrm{max}}v(\\theta^{(g)}, \\theta^{(d)})\n", - "\\label{_auto10} \\tag{12}\n", + "\\label{_auto7} \\tag{7}\n", "\\end{equation}\n", "$$" ] }, { "cell_type": "markdown", - "id": "4acc410f", + "id": "cab152e1", "metadata": { "editable": true }, @@ -2937,7 +2498,7 @@ }, { "cell_type": "markdown", - "id": "0d39c52d", + "id": "3492fec2", "metadata": { "editable": true }, @@ -2958,7 +2519,7 @@ }, { "cell_type": "markdown", - "id": "fdcd9cbe", + "id": "283a367b", "metadata": { "editable": true }, @@ -2974,8 +2535,8 @@ }, { "cell_type": "code", - "execution_count": 20, - "id": "d26da506", + "execution_count": 18, + "id": "0c04c905", "metadata": { "collapsed": false, "editable": true @@ -2993,7 +2554,7 @@ }, { "cell_type": "markdown", - "id": "ea7cdc02", + "id": "907cefc2", "metadata": { "editable": true }, @@ -3003,8 +2564,8 @@ }, { "cell_type": "code", - "execution_count": 21, - "id": "c7eb4802", + "execution_count": 19, + "id": "286218f8", "metadata": { "collapsed": false, "editable": true @@ -3030,7 +2591,7 @@ }, { "cell_type": "markdown", - "id": "c1d5fec0", + "id": "0f85cb57", "metadata": { "editable": true }, @@ -3042,8 +2603,8 @@ }, { "cell_type": "code", - "execution_count": 22, - "id": "e127c9d1", + "execution_count": 20, + "id": "7c99596c", "metadata": { "collapsed": false, "editable": true @@ -3056,7 +2617,7 @@ }, { "cell_type": "markdown", - "id": "f22b1f34", + "id": "5acb88c4", "metadata": { "editable": true }, @@ -3074,8 +2635,8 @@ }, { "cell_type": "code", - "execution_count": 23, - "id": "c4a2cacd", + "execution_count": 21, + "id": "8caa7692", "metadata": { "collapsed": false, "editable": true @@ -3143,7 +2704,7 @@ }, { "cell_type": "markdown", - "id": "480f02a0", + "id": "685bdcc0", "metadata": { "editable": true }, @@ -3155,8 +2716,8 @@ }, { "cell_type": "code", - "execution_count": 24, - "id": "f72030bf", + "execution_count": 22, + "id": "086989bd", "metadata": { "collapsed": false, "editable": true @@ -3196,7 +2757,7 @@ }, { "cell_type": "markdown", - "id": "75bb7754", + "id": "60d7d28d", "metadata": { "editable": true }, @@ -3207,8 +2768,8 @@ }, { "cell_type": "code", - "execution_count": 25, - "id": "21ea4886", + "execution_count": 23, + "id": "e6e04456", "metadata": { "collapsed": false, "editable": true @@ -3221,8 +2782,8 @@ }, { "cell_type": "code", - "execution_count": 26, - "id": "0e2ff6b7", + "execution_count": 24, + "id": "047fda01", "metadata": { "collapsed": false, "editable": true @@ -3235,7 +2796,7 @@ }, { "cell_type": "markdown", - "id": "92de7dad", + "id": "07d7aff7", "metadata": { "editable": true }, @@ -3245,8 +2806,8 @@ }, { "cell_type": "code", - "execution_count": 27, - "id": "43248ee2", + "execution_count": 25, + "id": "7cd7291c", "metadata": { "collapsed": false, "editable": true @@ -3260,7 +2821,7 @@ }, { "cell_type": "markdown", - "id": "b7312ee0", + "id": "bb02c980", "metadata": { "editable": true }, @@ -3274,8 +2835,8 @@ }, { "cell_type": "code", - "execution_count": 28, - "id": "e367ad5d", + "execution_count": 26, + "id": "590ec096", "metadata": { "collapsed": false, "editable": true @@ -3290,8 +2851,8 @@ }, { "cell_type": "code", - "execution_count": 29, - "id": "7e402451", + "execution_count": 27, + "id": "9bbe545f", "metadata": { "collapsed": false, "editable": true @@ -3308,7 +2869,7 @@ }, { "cell_type": "markdown", - "id": "448c67f3", + "id": "3f1de735", "metadata": { "editable": true }, @@ -3319,8 +2880,8 @@ }, { "cell_type": "code", - "execution_count": 30, - "id": "9f56c662", + "execution_count": 28, + "id": "973fdf50", "metadata": { "collapsed": false, "editable": true @@ -3334,7 +2895,7 @@ }, { "cell_type": "markdown", - "id": "2c51f0c5", + "id": "dee6ff89", "metadata": { "editable": true }, @@ -3349,8 +2910,8 @@ }, { "cell_type": "code", - "execution_count": 31, - "id": "f9391797", + "execution_count": 29, + "id": "aafdd8b1", "metadata": { "collapsed": false, "editable": true @@ -3384,7 +2945,7 @@ }, { "cell_type": "markdown", - "id": "6e74397f", + "id": "cbd5410d", "metadata": { "editable": true }, @@ -3396,8 +2957,8 @@ }, { "cell_type": "code", - "execution_count": 32, - "id": "669b18b3", + "execution_count": 30, + "id": "f4e201f7", "metadata": { "collapsed": false, "editable": true @@ -3422,7 +2983,7 @@ }, { "cell_type": "markdown", - "id": "05ae82e4", + "id": "d6d01665", "metadata": { "editable": true }, @@ -3435,8 +2996,8 @@ }, { "cell_type": "code", - "execution_count": 33, - "id": "08601a15", + "execution_count": 31, + "id": "310a2c04", "metadata": { "collapsed": false, "editable": true @@ -3454,7 +3015,7 @@ }, { "cell_type": "markdown", - "id": "7aff5339", + "id": "1d39eca5", "metadata": { "editable": true }, @@ -3464,8 +3025,8 @@ }, { "cell_type": "code", - "execution_count": 34, - "id": "c6a3091a", + "execution_count": 32, + "id": "f38e5564", "metadata": { "collapsed": false, "editable": true @@ -3505,7 +3066,7 @@ }, { "cell_type": "markdown", - "id": "144394bb", + "id": "83fd51ec", "metadata": { "editable": true }, @@ -3516,8 +3077,8 @@ }, { "cell_type": "code", - "execution_count": 35, - "id": "82e28e91", + "execution_count": 33, + "id": "9e85b452", "metadata": { "collapsed": false, "editable": true @@ -3529,7 +3090,7 @@ }, { "cell_type": "markdown", - "id": "78c55210", + "id": "8908bca0", "metadata": { "editable": true }, @@ -3542,8 +3103,8 @@ }, { "cell_type": "code", - "execution_count": 36, - "id": "cbbe6dca", + "execution_count": 34, + "id": "af4a6a84", "metadata": { "collapsed": false, "editable": true @@ -3560,7 +3121,7 @@ }, { "cell_type": "markdown", - "id": "88fd9f62", + "id": "43e8fe94", "metadata": { "editable": true }, @@ -3573,8 +3134,8 @@ }, { "cell_type": "code", - "execution_count": 37, - "id": "c77ff08b", + "execution_count": 35, + "id": "1564f933", "metadata": { "collapsed": false, "editable": true @@ -3591,7 +3152,7 @@ }, { "cell_type": "markdown", - "id": "b90bab7f", + "id": "168fe9b5", "metadata": { "editable": true }, @@ -3606,8 +3167,8 @@ }, { "cell_type": "code", - "execution_count": 38, - "id": "b0ca2c76", + "execution_count": 36, + "id": "90cdc927", "metadata": { "collapsed": false, "editable": true @@ -3634,8 +3195,8 @@ }, { "cell_type": "code", - "execution_count": 39, - "id": "97b52ae8", + "execution_count": 37, + "id": "12b0438d", "metadata": { "collapsed": false, "editable": true @@ -3657,8 +3218,8 @@ }, { "cell_type": "code", - "execution_count": 40, - "id": "1836696a", + "execution_count": 38, + "id": "1fd8fc99", "metadata": { "collapsed": false, "editable": true @@ -3671,7 +3232,7 @@ }, { "cell_type": "markdown", - "id": "1e056da7", + "id": "0ad51825", "metadata": { "editable": true }, @@ -3686,8 +3247,8 @@ }, { "cell_type": "code", - "execution_count": 41, - "id": "870bc291", + "execution_count": 39, + "id": "8502439f", "metadata": { "collapsed": false, "editable": true @@ -3714,7 +3275,7 @@ }, { "cell_type": "markdown", - "id": "b0bbfc38", + "id": "a973cf5f", "metadata": { "editable": true }, @@ -3728,8 +3289,8 @@ }, { "cell_type": "code", - "execution_count": 42, - "id": "d6e3d3ed", + "execution_count": 40, + "id": "e491437f", "metadata": { "collapsed": false, "editable": true @@ -3745,7 +3306,7 @@ }, { "cell_type": "markdown", - "id": "fdd6af9e", + "id": "24884da9", "metadata": { "editable": true }, @@ -3756,7 +3317,7 @@ }, { "cell_type": "markdown", - "id": "57421271", + "id": "5091d2c3", "metadata": { "editable": true }, @@ -3773,8 +3334,8 @@ }, { "cell_type": "code", - "execution_count": 43, - "id": "e7c46c78", + "execution_count": 41, + "id": "39edd67f", "metadata": { "collapsed": false, "editable": true @@ -3792,7 +3353,7 @@ }, { "cell_type": "markdown", - "id": "04c4f696", + "id": "31e70f2b", "metadata": { "editable": true }, @@ -3802,8 +3363,8 @@ }, { "cell_type": "code", - "execution_count": 44, - "id": "5afb7eee", + "execution_count": 42, + "id": "fd075112", "metadata": { "collapsed": false, "editable": true diff --git a/doc/src/week43/week43.do.txt b/doc/src/week43/week43.do.txt index efded1bc3..09761452b 100644 --- a/doc/src/week43/week43.do.txt +++ b/doc/src/week43/week43.do.txt @@ -366,225 +366,7 @@ We rather code the convolutions in the minimal memory footprint that they requir Does the number of floating point operations change here when we use the commutative property? -!split -===== Convolution Examples: Principle of Superposition and Periodic Forces (Fourier Transforms) ===== -For problems with so-called harmonic oscillations, given by for example the following differential equation -!bt -\[ -m\frac{d^2x}{dt^2}+\eta\frac{dx}{dt}+x(t)=F(t), -\] -!et -where $F(t)$ is an applied external force acting on the system (often called a driving force), one can use the theory of Fourier transformations to find the solutions of this type of equations. - -If one has several driving forces, $F(t)=\sum_n F_n(t)$, one can find -the particular solution to each $F_n$, $x_{pn}(t)$, and the particular -solution for the entire driving force is then given by a series like - -!bt -\begin{equation} -x_p(t)=\sum_nx_{pn}(t). -\end{equation} -!et - -!split -===== Principle of Superposition ===== - -This is known as the principle of superposition. It only applies when -the homogenous equation is linear. If there were an anharmonic term -such as $x^3$ in the homogenous equation, then when one summed various -solutions, $x=(\sum_n x_n)^2$, one would get cross -terms. Superposition is especially useful when $F(t)$ can be written -as a sum of sinusoidal terms, because the solutions for each -sinusoidal (sine or cosine) term is analytic. - -Driving forces are often periodic, even when they are not -sinusoidal. Periodicity implies that for some time $\tau$ - -!bt -\begin{eqnarray} -F(t+\tau)=F(t). -\end{eqnarray} -!et - -One example of a non-sinusoidal periodic force is a square wave. Many -components in electric circuits are non-linear, e.g. diodes, which -makes many wave forms non-sinusoidal even when the circuits are being -driven by purely sinusoidal sources. - -!split -===== Simple Code Example ===== - -The code here shows a typical example of such a square wave generated using the functionality included in the _scipy_ Python package. We have used a period of $\tau=0.2$. - -!bc pycod -import numpy as np -import math -from scipy import signal -import matplotlib.pyplot as plt - -# number of points -n = 500 -# start and final times -t0 = 0.0 -tn = 1.0 -# Period -t = np.linspace(t0, tn, n, endpoint=False) -SqrSignal = np.zeros(n) -SqrSignal = 1.0+signal.square(2*np.pi*5*t) -plt.plot(t, SqrSignal) -plt.ylim(-0.5, 2.5) -plt.show() -!ec - - -For the sinusoidal example the -period is $\tau=2\pi/\omega$. However, higher harmonics can also -satisfy the periodicity requirement. In general, any force that -satisfies the periodicity requirement can be expressed as a sum over -harmonics, - -!bt -\begin{equation} -F(t)=\frac{f_0}{2}+\sum_{n>0} f_n\cos(2n\pi t/\tau)+g_n\sin(2n\pi t/\tau). -\end{equation} -!et - -!split -===== Wrapping up Fourier transforms ===== - -We can write down the answer for -$x_{pn}(t)$, by substituting $f_n/m$ or $g_n/m$ for $F_0/m$. By -writing each factor $2n\pi t/\tau$ as $n\omega t$, with $\omega\equiv -2\pi/\tau$, - -!bt -\begin{equation} -label{eq:fourierdef1} -F(t)=\frac{f_0}{2}+\sum_{n>0}f_n\cos(n\omega t)+g_n\sin(n\omega t). -\end{equation} -!et - -The solutions for $x(t)$ then come from replacing $\omega$ with -$n\omega$ for each term in the particular solution, - -!bt -\begin{eqnarray} -x_p(t)&=&\frac{f_0}{2k}+\sum_{n>0} \alpha_n\cos(n\omega t-\delta_n)+\beta_n\sin(n\omega t-\delta_n),\\ -\nonumber -\alpha_n&=&\frac{f_n/m}{\sqrt{((n\omega)^2-\omega_0^2)+4\beta^2n^2\omega^2}},\\ -\nonumber -\beta_n&=&\frac{g_n/m}{\sqrt{((n\omega)^2-\omega_0^2)+4\beta^2n^2\omega^2}},\\ -\nonumber -\delta_n&=&\tan^{-1}\left(\frac{2\beta n\omega}{\omega_0^2-n^2\omega^2}\right). -\end{eqnarray} -!et - -!split -===== Finding the Coefficients ===== - -Because the forces have been applied for a long time, any non-zero -damping eliminates the homogenous parts of the solution, so one need -only consider the particular solution for each $n$. - -The problem is considered solved if one can find expressions for the -coefficients $f_n$ and $g_n$, even though the solutions are expressed -as an infinite sum. The coefficients can be extracted from the -function $F(t)$ by - -!bt -\begin{eqnarray} -label{eq:fourierdef2} -f_n&=&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~F(t)\cos(2n\pi t/\tau),\\ -\nonumber -g_n&=&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~F(t)\sin(2n\pi t/\tau). -\end{eqnarray} -!et - -To check the consistency of these expressions and to verify -Eq. (ref{eq:fourierdef2}), one can insert the expansion of $F(t)$ in -Eq. (ref{eq:fourierdef1}) into the expression for the coefficients in -Eq. (ref{eq:fourierdef2}) and see whether - -!bt -\begin{eqnarray} -f_n&=?&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~\left\{ -\frac{f_0}{2}+\sum_{m>0}f_m\cos(m\omega t)+g_m\sin(m\omega t) -\right\}\cos(n\omega t). -\end{eqnarray} -!et - -Immediately, one can throw away all the terms with $g_m$ because they -convolute an even and an odd function. The term with $f_0/2$ -disappears because $\cos(n\omega t)$ is equally positive and negative -over the interval and will integrate to zero. For all the terms -$f_m\cos(m\omega t)$ appearing in the sum, one can use angle addition -formulas to see that $\cos(m\omega t)\cos(n\omega -t)=(1/2)(\cos[(m+n)\omega t]+\cos[(m-n)\omega t]$. This will integrate -to zero unless $m=n$. In that case the $m=n$ term gives - -!bt -\begin{equation} -\int_{-\tau/2}^{\tau/2}dt~\cos^2(m\omega t)=\frac{\tau}{2}, -\end{equation} -!et - -and - -!bt -\begin{eqnarray} -f_n&=?&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~f_n/2\\ -\nonumber -&=&f_n~\checkmark. -\end{eqnarray} -!et - -The same method can be used to check for the consistency of $g_n$. - - - -!split -===== Final words on Fourier Transforms ===== - -The code here uses the Fourier series applied to a -square wave signal. The code here -visualizes the various approximations given by Fourier series compared -with a square wave with period $T=0.2$ (dimensionless time), width $0.1$ and max value of the force $F=2$. We -see that when we increase the number of components in the Fourier -series, the Fourier series approximation gets closer and closer to the -square wave signal. - -!bc pycod -import numpy as np -import math -from scipy import signal -import matplotlib.pyplot as plt - -# number of points -n = 500 -# start and final times -t0 = 0.0 -tn = 1.0 -# Period -T =0.2 -# Max value of square signal -Fmax= 2.0 -# Width of signal -Width = 0.1 -t = np.linspace(t0, tn, n, endpoint=False) -SqrSignal = np.zeros(n) -FourierSeriesSignal = np.zeros(n) -SqrSignal = 1.0+signal.square(2*np.pi*5*t+np.pi*Width/T) -a0 = Fmax*Width/T -FourierSeriesSignal = a0 -Factor = 2.0*Fmax/np.pi -for i in range(1,500): - FourierSeriesSignal += Factor/(i)*np.sin(np.pi*i*Width/T)*np.cos(i*t*2*np.pi/T) -plt.plot(t, SqrSignal) -plt.plot(t, FourierSeriesSignal) -plt.ylim(-0.5, 2.5) -plt.show() -!ec !split