\magnification=\magstep1
\vsize=9truein
\hsize=6.5truein
%\parindent=0.8truein
\def\C{{\bf C}}
\def\R{{\bf R}}
\def\N{{\bf N}}
\def\span{{\rm span}}
\font\sc=cmcsc10
\font\smalltt=cmtt10 scaled840
\font\smseven=cmr7 scaled840

\newcount\qnum\newcount\qprt\qnum=0\qprt=0
\newcount\ano
\def\qn{\ano=0\global\qprt=0\global\advance\qnum by1\medskip
    \par\noindent\item{\bf\the\qnum.}}
\def\cqnn{\ano=0\global\advance\qprt by1\par
    \par\noindent\itemitem{\bf(\romannumeral\qprt)}}
\def\qnn{\ano=0\global\advance\qprt by1\medskip
    \par\noindent\itemitem{\bf(\romannumeral\qprt)}}

%verbatim environment
\def\uncatcodespecials{\def\do##1{\catcode`##1=12 }\dospecials}
\newcount\lineno
\def\listing#1{\par\begingroup\setupverbatim #1\endgroup}
\def\setupverbatimc{\parindent=1truecm\tt
%   \smalltt\baselineskip=10pt plus 1pt minus 1pt
    \def\par{\leavevmode\endgraf}\catcode`\`=\active\obeylines
    \uncatcodespecials\obeyspaces
    \everypar{\global\advance\lineno by 1\llap{\smseven\the\lineno\ \ }}}
\def\setupverbatimb{\parindent=1truecm
    \global\lineno=0\smalltt\baselineskip=10pt plus 1pt minus 1pt
    \def\par{\leavevmode\endgraf}\catcode`\`=\active\obeylines
    \uncatcodespecials\obeyspaces
    \everypar{\advance\lineno by 1{}}}
\def\setupverbatim{\global\lineno=0\setupverbatimc}

{\obeyspaces\global\let =\ }

\def\beginverbatim{\par\begingroup\setupverbatim\doverbatim}
{\catcode`\|=0\catcode`\\=12\catcode`|`=|active|gdef`{|relax|lq}%
|obeylines|gdef|doverbatim^^M#1\endverbatim{#1|endgroup}}

\def\beginverbatimb{\par\begingroup\setupverbatimb\doverbatim}
\def\listing#1{\medskip
    \begingroup\setupverbatim\input#1\endgroup\medskip
    \noindent\ignorespaces}
\def\listout#1{\medskip
    \begingroup\setupverbatimb\input#1\endgroup\medskip
    \noindent\ignorespaces}
\def\macinput#1{{\catcode`\$=10\catcode`@=3 \input #1 }}

\input epsf

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\headline{{\bf Math 702\hfil Programming Assignment 2 Solutions}}

\qn Consider the nonlinear Schr\"odinger equation
$$
\cases{iv_t=v_{xx}+2|v|^2v& for $(x,t)\in \R\times (0,T)$\cr
	v(x,0)=f(x) & for $x\in\R$.\cr
}$$
Suppose for some $L>0$ that $f(x)=f(x+L)$ for $x\in\R$.  Prove
the resulting solution~$v$ satisfies $v(x,t)=v(x+L,t)$ 
for all $(x,t)\in\R\times (0,T)$.  
We shall say that $v$ satisfies 
the nonlinear Schr\"odinger equation
with $L$-periodic boundary conditions.
\bigskip\noindent
Consider the function $w(x,t)=v(x+L,t)$.  Since $f$ is $L$-periodic
we have 
$$w(x,0)=v(x+L,0)=f(x+L)=f(x).$$  By the chain rule
$$
	w_{xx}(x,t)={\partial^2\over \partial x^2} v(x+L,t)
		=v_{xx}(x+L,t).
$$
Therefore $w(x,t)$ satisfies the differential equation
$$
\cases{iw_t=w_{xx}+2|w|^2w& for $(x,t)\in \R\times (0,T)$\cr
	w(x,0)=f(x) & for $x\in\R$.\cr
}$$
Uniquencess of solutions implies that $w(x,t)=v(x,t)$.
Therefore $v(x,t)=v(x+L,t)$ for all $(x,t)\in\R\times(0,T)$
which was to be shown.
\vfill\eject	

\qn Let $v$ be a solution to the nonlinear Schr\"odinger
equation with $L$-periodic boundary conditions.
Let $\Delta x=L/K$ and $\Delta t=T/N$ and
consider the finite difference method for approximating
$v$ on $[0,L]\times[0,T]$ given by
$$
\cases{
	\displaystyle u_k^{n+1}=u_k^{n-1} 
		- {2i\Delta t\over \Delta x^2} \delta^2 u_k^n
		- 4i\Delta t |u_{k}^n|^2 u_{k}^n
	& for $n=1,\ldots,N-1$\cr
	& and $k=1,\ldots,K$\cr
	\displaystyle u_k^{1}=u_k^{0} 
		- {i\Delta t\over \Delta x^2} \delta^2 u_k^0
		- 2i\Delta t |u_{k}^0|^2 u_{k}^0&
		for $k=1,\ldots,K$\cr
\noalign{\medskip}
	u_0^{n}=u_K^{n}\quad{\rm and}\quad 
	u_{K+1}^n=u_1^n& for $n=0,\ldots,N$\cr
\noalign{\medskip}
	u_k^0=f(k\Delta x)& for $k=1,\ldots,K$.\cr
}$$
For $L=10$ and $T=0.2$ choose $K$ and $N$ sufficiently large
to approximate $v(5,0.2)$ to at least 3 significant
digits for the personalized initial condition $f$ given below
$$\eqalign{
	f_{\rm Alexander}(x)&
		=2\exp\!\big(3i\sin(\omega x)\big)+\sin(3\omega x)\cr
	f_{\rm Anthony}(x)&
		=\exp(i\omega x)-\sin(2\omega x)+\exp(5i\omega x)\cr
	f_{\rm Brian}(x)&
		=0.5\exp(i\omega x)+0.5\sin(2\omega x)-2i\cos(3\omega x)\cr
	f_{\rm Jordan}(x)&
		=2\exp(-i\omega x)-i\cos(3\omega x)\cr
	f_{\rm Joseph}(x)&
		=0.5\exp(i\omega x)-\exp(2i\omega x)+i\exp(3i\omega x)
			+0.5\exp(5i\omega x) \cr
	f_{\rm Kyle}(x)&
		=i\sin(\omega x)+\cos(2\omega x)+\exp(-3i\omega x)\cr
	f_{\rm Masakazu}(x)&
		=1+\exp(i\omega x)\cr
	f_{\rm Sarah}(x)&
		=\exp(i\omega x)+\exp(-2i\omega x)+\exp(3i\omega x)\cr
	f_{\rm Shijie}(x)&
		=\sin\!\big(3\cos(\omega x)\big)+2\exp(2i\omega x)\cr
}$$
where $\omega=\pi/5$.
\bigskip\noindent
To implement these scheme the driver and common routines were
factored into the file{\tt\ utility.c }with header{\tt\ utility.h }while
the file named{\tt\ classical.c }was used for the method itself.
The driver and common routines are
\listing{utility.c}
with header
\listing{utility.h}
and the classical explicit method was coded as
\listing{classical.c}
The output is
\listout{classical.dat}
Note that values for $N$ and $K$ were chosen as a trade off between
accuracy, stability and computational time.  The output is
consistent with the output from the more efficient methods used
in the next secions.
\vfill\eject

\qn Approximate $v(5,0.2)$ using one of the other methods found, for example, in
\medskip
\itemitem{}Thiab R. Taha, Mark J. Ablowitz, Analytical and Numerical Aspects
of Certain Nonlinear Evolution Equations II: Numerical, Nonlinear
Schr\"odinger Equation, {\it J.{\ }Comput.{\ }Phys.}, {\bf 55} (1984),
pp.{\ }203--230.
\medskip
\hangindent\parindent
Please include a bibliographic reference to the method you implemented
as a comment in your source code.
\bigskip
\noindent
I implemented the hopscotch method 1(a)(ii) and the
split step Fourier method 2(i) following Taha and Ablowitz.
The code for the hopscotch method is
\listing{hopscotch.c}
with output
\listout{hopscotch.dat}
and the code for the split step Fourier method is
\listing{split.c}
with output
\listout{split.dat}
Note the two methods yield results consistent with Part 2.
\vfill\eject
\end
