\documentclass[titlepage,a4paper,12pt,english]{IMFeksamen}
\usepackage[utf8]{inputenc}
\usepackage{setspace} % erstatt evt utf8 med latin1
\trykkinfo[tosidig,sorthvit] % [ensidig,farger]
\emnekode{TMA4130/35}
\emnenavn{Mathematics 4N/4D}
\eksamensdato{December 02 2019}
\eksamenstid{09:00–13:00}
\fagligkontaktinfo{Helge Holden}{92 03 86 25}
\fagligkontaktinfo{Peter Ho Cheung Pang}{41 34 74 46}
\fagligkontaktinfo{Xu Wang}{94 43 03 43}
\hjelpemiddel{Code C: Approved calculator \\
One yellow, stamped A5 sheet with own handwritten formulas and notes (on both sides)}
\anneninfo{\begin{itemize}
\item All answers have to be justified, and they should include enough details in order to see how they have been obtained.
\item There are two versions of Problem 3: one for Mathematics 4N and one for Mathematics 4D. 
\item Good Luck!
\end{itemize}}
\runninghead{TMA4130/35 Mathematics 4N/D, December 2019 }
\usepackage[T1]{fontenc}
\usepackage{lmodern,amsmath,amssymb,amsfonts}
\usepackage{color}
\definecolor{mygray}{rgb}{0.9,0.9,0.9}
\usepackage{listings}
\lstset{language=python, basicstyle=\ttfamily}
\lstset{linewidth=0.8\textwidth, showstringspaces=false}
\lstset{backgroundcolor=\color{mygray}}
\newcommand{\mb}[1]{\mathbf{#1}}

\begin{document}

\begin{oppgave} {[20 points]}
        
        \begin{punkt} 
 	Compute the Laplace transform of 
	$$
		f(t)=
		\begin{cases}
		0  &  0\leq t\leq 1, \\ 
		t &  t>1 .  
		\end{cases}
	$$	 
  	\end{punkt}
  	
  	
  
  
        
        
        \begin{punkt}  Use the Laplace transform to find the solution of 
	$$
		y''+y=2e^t \hspace{1cm} {\mathrm{with}}\  y(0)=y'(0)=0.
	$$
  	\end{punkt}
  	
  	
  	
  	
  	
  	
  	        \begin{punkt} 
        Compute the inverse Laplace transform $\mathcal{L}^{-1}(F)(t)$ of the following function
        $$
        F(s)=\frac{1}{s^2+2s+17}.
        $$
         \end{punkt}
         
        
          \end{oppgave}
          
          
         
         
          \begin{oppgave}   { [14 points] }
   
   \begin{punkt} Let
          $$
f(x)=1+x, \ \ -\pi <x<\pi.          
          $$
          Verify the following complex Fourier series expansion for $f$
     $$
    1+\sum_{n\neq 0} \frac{i(-1)^n}{n} e^{inx}.   
     $$  
   \end{punkt}
   
\begin{punkt}
Why is 
 $$
    f(x)=1+\sum_{n\neq 0} \frac{i(-1)^n}{n} e^{inx} 
     $$  
     for $-\pi <x<\pi$? 
 \end{punkt}   
  
   
   
   \begin{punkt}
   Compute the Fourier transform of
   $$
f(x)= 
\begin{cases}
\sin (x) & |x|<1, \\
0 & |x|\geq 1.
\end{cases}
   $$
     \end{punkt}
     

   
 \end{oppgave}
	






\begin{oppgave} {\textit{TMA4130 Mathematics 4N: }  } [6 points] 
  
Solve the initial value problem for the wave equation  
($u_{tt}=\partial^2 u/\partial t^2, \ u_{xx}=\partial^2 u/ \partial x^2, \ u_{t}=\partial u/\partial t$ mean partial derivatives) 
$$
u_{tt}=u_{xx}, \ \ u(x,0)=\sin (x), \ \ u_t(x,0)=e^x,
$$    
using d'Alembert's solution.   
\end{oppgave}


\addtocounter{Oppg}{-1} 

\begin{oppgave} {\textit{TMA4135 Mathematics 4D: }}  [6 points]

       Show that the following function $u(x,t)=(x-t)^3+\sin(x+t)$ 
	satisfies the wave equation  $u_{xx}=u_{tt}$ ($u_{tt}=\partial^2 u/\partial t^2, \ u_{xx}=\partial^2 u/ \partial x^2$ mean partial derivatives). 
	
\end{oppgave}



\begin{oppgave} { [20 points] }
        
       Consider the following heat equation
   $$
u_t(x,t) =\frac12 u_{xx}(x,t),   \ \  t\geq 0, \ \ \ 0\leq x\leq \pi,
   $$
 with boundary conditions
   $$
u(0, t)=u(\pi, t)=0,  \ \ t\geq 0;   
   $$
   and the initial condition
   $$
u(x, 0)= x(\pi-x), \  \ 0\leq x\leq \pi.
   $$
   
    \begin{punkt} Find the Fourier sine series solution of the above heat equation by using the separation of variables method.
\end{punkt}  



 \begin{punkt} Let $M,N$ be two natural numbers, and define $h=\pi/M$ and $k=1/N$. Introduce $x_i=ih$ for $i=0,\dots,M$ and $t_n=nk$ for $n=0,1,2,\dots$.
Write down an explicit difference scheme (based on finite differences and (forward) Euler's method) for $U^n_i\approx u(x_i,t_n)$.
\end{punkt}  



 \begin{punkt} 
Let $M=4$ and $N=20$, and compute the approximate solution for $u(\pi/4,0.1)$.
\end{punkt}




% 	\begin{punkt}  Solve the following heat equation (you can use a) and b) above or other methods )
%   	$$
%		u_t =\frac12 u_{xx},   \ \  t\geq 0, \ \ \ 0\leq x\leq \pi,
%   	$$
%   	with the boundary conditions
%   	$$
%	u(t, 0)=u(t,\pi)=0,  \ \forall \ t\geq 0;   
%   	$$
%   	and the initial condition
%   	$$
%	u(0,x)= \sin 3x + \sin  5x, \ \forall \ 0\leq x\leq \pi;   
%   	$$
%   	\end{punkt}

\end{oppgave}


\begin{oppgave} { [10 points] }

    Find $a,b,c,d$ such that the polynomial 
    $$
    p(x)=ax^3+bx^2+cx+d
    $$ 
    interpolates the points 
    \[
      \begin{array}{c|cccc}
	x_i & 0 & 2 & 3 & 4 \\ \hline
	y_i & 1 & 5 & 10 & 17 
      \end{array}.
    \]

\end{oppgave}



\begin{oppgave} { [10 points] }

 The integral 
  \[ 
    \int_{0}^1 f(x) \, dx,
  \]
  can be approximated by the Simpson formula
  \[ 
    S = \frac{1}{6}\bigg(f(0)+4f(0.5)+f(1)\bigg).
  \]

  
    \begin{punkt}   
      Apply the Simpson formula to the integral
      \[ 
      	\int_0^1 x^3 \, dx.
      \]
      \end{punkt}
      
  
      
  
     \begin{punkt}  
       Determine the degree of precision for the Simpson formula.
     \end{punkt}
     
    
     
     
  
  
\end{oppgave}

\begin{oppgave} {[10 points]}

Let $r$ be the solution of the following equation
$$
x+\ln (x-1)=0, \ \  1<x<2.
$$
Show that the solution is unique. Starting from
$$
x_0=1.25,
$$
apply one step of Newton's iteration, and compute $x_1$.
  
\end{oppgave}



\begin{oppgave} { [10 points]}

Heun's method is given by:
  \begin{align*}
    \mb{k}_1 &= \mb{f}(x_n, \mb{y}_n), \\
    \mb{k}_2 &= \mb{f}(x_n+h, \mb{y}_n+h\mb{k}_1), \\
    \mb{y}_{n+1} &= \mb{y}_n + \frac h2  (\mb{k}_1+\mb{k}_2).
  \end{align*}
  \begin{punkt}
    Apply one step with step size $h=0.1$ using the above method on the problem:
    $$
      y' = -2xy,  \ \ \ y(0) = 1. 
    $$
    Find the exact solution of the above equation and compute the error.
  \end{punkt}
  

  
  \begin{punkt}
    Find the stability function $R(z)$ for Heun's method. Find also the corresponding stability
    interval. 
  \end{punkt}
  

\end{oppgave}




\begin{comment}\begin{oppgave} {\underline{Optional}} 

Verify the following Laplace transform formula of the heat kernel:

$$
\int_{0}^\infty  \frac{1}{\sqrt{2\pi t}} e^{-\frac{x^2}{2t}}       e^{-ts} \, dt=\frac{1}{\sqrt{2s}} e^{-|x|\sqrt{2s}}, \ \ s>0.
$$ 


--- Compute by force is fine (but not easy!). Fix $s>0$. Put
$$
g(x)=\int_{0}^\infty  \frac{1}{\sqrt{2\pi t}} e^{-\frac{x^2}{2t}} e^{-ts} \, dt
$$
It is easy to see that the Gaussian integral gives
$$
g(0)=\frac{1}{\sqrt{2s}}.
$$
Moreover, since $g$ is even it is enough to prove the $x>0$ case. Since the heat kernel satisfies $h_t=\frac12 h_{xx}$, integration by parts gives
$$
g''(x)= 2s g(x).
$$
Thus  for $x>0$, we have
$$
g(x)=A e^{-x\sqrt{2s}}+  B e^{x\sqrt{2s}}.
$$
Now
$$
\lim_{x\to \infty} g(x)=0
$$
gives
$$
B=0.
$$
Together with the formula for $g(0)$, our result follows. 

\end{oppgave}
\end{comment}

 


%--------------------------------------------------------------------------------------
\vedlegg
\subsection*{Fourier Transform}

\begin{center}
\begin{tabular}{c|c}
 ${\displaystyle f(x) = \frac{1}{\sqrt{2\pi}}\int_{-\infty}^{\infty} \hat f(w)e^{iw x}\text{
d}w}$& ${\displaystyle \hat f(w) = \frac{1}{\sqrt{2\pi}}\int_{-\infty}^{\infty} f(x)e^{-iw x}\text{ d}x}$  \\ \\[-1em]
 \hline\hline \\[-1em]
% $f*g(x)$ & $ \sqrt{2\pi}\hat f(w)\hat g(\omega)$\\ \\[-1em] \hline
% \\[-1em]
% $f'(x)$ & $ iw\hat f(\omega)$\\ \\[-1em] \hline 
% \\[-1em]
 $e^{-ax^2}$ & ${\displaystyle \frac{1}{\sqrt{2a}} e^{-w^2/4a}}$\\ \\[-1em] \hline
 \\[-1em]
 $e^{-a|x|}$ & $ {\displaystyle \sqrt{\frac{2}{\pi}}\frac{a}{w^2+a^2}}$\\ \\[-1em] \hline
 \\[-1em]
 ${\displaystyle \frac{1}{x^2+a^2}}$ & $ {\displaystyle \sqrt{\frac{\pi}{2}}\frac{e^{-a|w|}}{a}}$\\ \\[-1em] \hline
 \\[-1em]
 ${\displaystyle \begin{cases} 1 & \text{for } |x|<a \\ 0 & \text{otherwise} \end{cases}}$ & ${\displaystyle \sqrt{\frac{2}{\pi}}\frac{\sin w a}{w}}$
\end{tabular}
\end{center}
\subsection*{Laplace Transform}
\begin{center}
\begin{tabular}{c|c}
 $f(t)$& ${\displaystyle F(s) = \int_0^{\infty} e^{-st} f(t) \text{ d}t}$  \\ \\[-1em]
 \hline\hline \\[-1em]
% $f'(t)$ & $ sF(s) - f(0)$\\ \\[-1em] \hline
% \\[-1em]
 %${\displaystyle \int_0^t f(\tau)\text{ d}\tau}$ & ${\displaystyle \frac{F(s)}{s}}$ \\ \\[-1em] \hline
% \\[-1em]
% $tf(t)$ & $ -F'(s)$\\ \\[-1em] \hline 
% \\[-1em]
% $e^{at}f(t)$ & $F(s-a)$\\ \\[-1em] \hline
% \\[-1em]
 $\cos(\omega t)$ & $ {\displaystyle \frac{s}{s^2+\omega^2}}$\\ \\[-1em] \hline
 \\[-1em]
 $\sin(\omega t)$ & $ {\displaystyle \frac{\omega}{s^2+\omega^2}}$\\ \\[-1em] \hline
 \\[-1em]
 $\cosh(\omega t)$ & $ {\displaystyle \frac{s}{s^2-\omega^2}}$\\ \\[-1em] \hline
 \\[-1em]
 $\sinh(\omega t)$ & $ {\displaystyle \frac{\omega}{s^2-\omega^2}}$\\ \\[-1em] \hline
 \\[-1em]
 $t^n$ & $ {\displaystyle \frac{\Gamma(n+1)}{s^{n+1}}}$,\\
 	  & {\tiny{for $n=0,1,2,\ldots$, $\Gamma(n+1)=n!$}} \\ \\[-1em] \hline
 \\[-1em]
$e^{at}$ & ${\displaystyle \frac{1}{s-a}}$\\ \\[-1em] \hline
 \\[-1em]
%$f(t-a)u(t-a)$ & $e^{-sa} F(s)$\\ \\[-1em] \hline
% \\[-1em]
$\delta(t-a)$ & $e^{-as}$\\ \\[-1em] \hline
 \\[-1em]
%$f*g(t)$ & $F(s)G(s)$
\end{tabular}
\end{center}
\mbox{} 
\nopagebreak
\begin{align*}
  \int x^n \cos ax \text{ d}x &= \frac{1}{a}x^n \sin ax - \frac{n}{a} \int x^{n-1} \sin ax \text{ d}x
  \\
  \int x^n \sin ax \text{ d}x &= -\frac{1}{a}x^n \cos ax + \frac{n}{a} \int x^{n-1} \cos ax \text{ d}x
\end{align*}

\section*{Numerics}

\begin{itemize}

 \item{Newton's method}: ${ x_{k+1} = x_k -\frac{f(x_k)}{f'(x_k)}}$.
 \item{Newton's method for system of equations}: $\vec x_{k+1} = \vec x_k -JF(\vec x_k)^{-1} F(\vec x_k)$, \\ with $JF = (\partial_j f_i)$.
 \item{Lagrange interpolation}: ${ p_n(x) = \sum_{k=0}^n\frac{l_k(x)}{l_k(x_k)} f_k}$, with ${ l_k(x) = \prod_{j\not = k} (x-x_j)}$.
 \item{Interpolation error}: ${ \epsilon_n(x) = \prod_{k=0}^n(x-x_k)\frac{f^{(n+1)}(t)}{(n+1)!}}$.
 \item{Chebyshev points}: ${ x_k = \cos\left(\frac{2k+1}{2n+2} \pi\right)}$, $0\leq k\leq n$. 
 \setstretch{1.2}{
\item{Newton's divided difference}: $f(x)\approx f_0 + (x-x_0)f[x_0, x_1] +$\\
$  (x-x_0)(x-x_1)f[x_0,x_1,x_2]+ \cdots + (x-x_0)(x-x_1)\cdots (x-x_{n-1})f[x_0,\ldots, x_n]$,\\
with ${ f[x_0,\ldots, x_k] = \frac{f[x_1,\ldots x_k] - f[x_0,\ldots, x_{k-1}]}{x_k-x_0}}$.}
\item {Trapezoid rule}: ${ \int_a^b f(x) \text{ d}x\approx h\left[\frac{1}{2}f(a) + f_1 + f_2 + \cdots + f_{n-1} + \frac{1}{2}f(b)\right]}$. \\
{Error of the trapezoid rule}: ${ |\epsilon|\leq \frac{b-a}{12} h^2 \max_{x\in [a,b]} |f''(x)|}$. 
 \item{Simpson rule}: ${ \int_a^b f(x) \text{ d}x\approx \frac{h}{3}\left[f_0 + 4f_1 + 2f_2 + 4f_3+\cdots + 2f_{n-2} + 4f_{n-1} + f_n \right]}$.\\
{Error of the Simpson rule}: ${ |\epsilon|\leq \frac{b-a}{180} h^4 \max_{x\in [a,b]} |f^{(4)}(x)|}$.
\item {Gauss--Seidel iteration}: ${ \textbf x^{(m+1)} = \textbf b-\textbf L\textbf x^{(m+1)} - \textbf U\textbf x^{(m)}}$,
with $\textbf A = \textbf I + \textbf L +\textbf U$. 
 \item{Jacobi iteration}: $\textbf x^{(m+1)} = \textbf b + (\textbf I-\textbf A)\textbf x^{(m)}$.
\item {Euler method}: $\textbf y_{n+1} = \textbf y_n + h\textbf f(x_n, \textbf y_n)$.
 \item{Improved Euler method}: ${ \textbf y_{n+1} = \textbf y_n + \frac{1}{2}h[\textbf f(x_n, \textbf y_n) + \textbf f(x_n+h, \textbf y^*_{n+1})]}$, where $\textbf y^*_{n+1} = \textbf y_n + h\textbf f(x_n, \textbf y_n)$. 
\item \setstretch{1.2}{{Classical Runge--Kutta method}: $\textbf k_1 = h\textbf f(x_n, \textbf y_n)$,\\
 $\textbf k_2 = h\textbf f(x_n+h/2, \textbf y_n + \textbf k_1/2)$,
  $\textbf k_3 = h\textbf f(x_n + h/2,  \textbf y_n + \textbf k_2/2)$,\\
  $\textbf k_4 = h \textbf f(x_n + h, \textbf y_n + \textbf k_3)$, $ \textbf y_{n+1} = \textbf y_n + \frac{1}{6}\textbf k_1 + \frac{1}{3} \textbf k_2 + \frac{1}{3} \textbf k_3 + \frac{1}{6} \textbf k_4$. }
\item {Backward Euler method}: $\textbf y_{n+1} = \textbf y_n + h\textbf f(x_{n+1}, \textbf y_{n+1})$. 
\item \setstretch{1.2}{{Finite differences}: ${ \frac{\partial u}{\partial x}(x,y)\approx\frac{u(x+h,y)-u(x-h,y)}{2h}}$, ${ \frac{\partial^2 u}{\partial x^2}(x,y)\approx\frac{u(x+h,y)-2u(x,y)+u(x-h,y)}{h^2}}$.}
\item Crank--Nicolson method for the heat equation: $r=\frac{k}{h^2}$, \\
$(2+2r)u_{i,j+1} - r(u_{i+1,j+1} + u_{i-1,j+1}) = (2-2r)u_{ij} + r(u_{i+1,j} + u_{i-1,j})$.
%${ \frac{\partial^2 u}{\partial y^2}(x,y)\approx\frac{u(x,y+h)-2u(x,y)+u(x,y-h)}{h^2}}$. }

\end{itemize}
\end{document}
