\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{algpseudocode}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{bm}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{color}
\usepackage{commath}
\usepackage{empheq}
\usepackage{epsfig}
\usepackage{framed}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{listings}
\usepackage{mathtools}
\usepackage{pdfpages}
\usepackage{pgfplots}
\usepackage{siunitx}
\usepackage{wrapfig}
\usepackage{hyperref}

\hypersetup{
    colorlinks=true,
    linkcolor=black,
    filecolor=black,
    urlcolor=black,
    citecolor=black,
}

% Command "alignedbox{}{}" for a box within an align environment
% Source: http://www.latex-community.org/forum/viewtopic.php?f=46&t=8144
\newlength\dlf  % Define a new measure, dlf
\newcommand\alignedbox[2]{
% Argument #1 = before & if there were no box (lhs)
% Argument #2 = after & if there were no box (rhs)
&  % Alignment sign of the line
{
\settowidth\dlf{$\displaystyle #1$}
    % The width of \dlf is the width of the lhs, with a displaystyle font
\addtolength\dlf{\fboxsep+\fboxrule}
    % Add to it the distance to the box, and the width of the line of the box
\hspace{-\dlf}
    % Move everything dlf units to the left, so that & #1 #2 is aligned under #1 & #2
\boxed{#1 #2}
    % Put a box around lhs and rhs
}
}
% Default fixed font does not support bold face
\DeclareFixedFont{\ttb}{T1}{txtt}{bx}{n}{12} % for bold
\DeclareFixedFont{\ttm}{T1}{txtt}{m}{n}{12}  % for normal
\DeclareMathOperator{\atantwo}{atan2}
\DeclareMathOperator{\acos}{acos}

\def\du#1{\underline{\underline{#1}}}

\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}

\lstdefinestyle{mystyle}{
    backgroundcolor=\color{backcolour},
    commentstyle=\color{codegreen},
    keywordstyle=\color{magenta},
    numberstyle=\tiny\color{codegray},
    stringstyle=\color{codepurple},
    basicstyle=\footnotesize,
    breakatwhitespace=false,
    breaklines=true,
    captionpos=b,
    keepspaces=true,
    numbers=left,
    numbersep=5pt,
    showspaces=false,
    showstringspaces=false,
    showtabs=false,
    tabsize=2
}

\lstset{style=mystyle}

\author{John Karasinski}
\title{Space Station Remote Manipulator System (SSRMS) Kinematics}

\begin{document}
\maketitle
\tableofcontents
\clearpage

\section{Introduction}

\begin{figure}[b!]
\includegraphics[width=\textwidth]{ssrms.jpg}
\caption{Orbital ATK's Cygnus cargo spacecraft is captured using the Canadarm2 robotic arm on the International Space Station~\cite{ssrms_cc}.}
\label{ssrms_image}
\end{figure}

The Space Station Remote Manipulator System (SSRMS) was designed and built to construct the International Space Station (ISS) and grapple with visiting space vehicles.
The SSRMS is a seven degree of freedom (DoF) manipulator consisting entirely of revolute joints.
The arm is symmetric, consisting of a 3DoF (roll, yaw, pitch) ``shoulder'', an ``elbow'' pitch joint, and a 3DoF (pitch, yaw, roll) ``wrist''.
Due to this symmetric structure, the arm has the ability to ``walk'' along the station, greatly increasing it's available working space.
The arm can lock the wrist to a grapple fixture, then disconnect the shoulder (which becomes the new wrist) to walk along the station.
See Figure~\ref{ssrms_image} for a picture of the arm grappling a visiting Cygnus vehicle.

The SSRMS is operating from one of the two Robotic Work Stations (RWS) located in either the Cupola or the Destiny module on the ISS.
While operating the arm from the RWS, astronauts commonly lock one of the shoulder joints, which allows for more predictable movement of the arm.
The shoulder roll is the most commonly locked joint during training and operation of the arm~\cite{astro_emails}.
For this reason, we will consider the shoulder roll joint (the first joint of the arm) to be locked at a fixed angle for the majority of this report.
We will begin by defining the D-H parameters and the transformation matrices for each joint, solve for the inverse kinematics, and then work through two different Jacobians.

\section{Finite Kinematic Analysis}
\subsection{Denavit-Hartenberg Parameters}
\begin{figure}[b!]
\includegraphics[width=\textwidth]{dh.jpg}
\caption{The Denavit-Hartenberg (D-H) parameters for the Space Station Remote Manipulator System (SSRMS)~\cite{xu2014analytical}.}
\label{dh_params}
\end{figure}

The Denavit-Hartenberg parameters form a minimal representation of a kinematic linkage of a robotic arm.
These four parameters are the joint angle, $\theta$, the link twist angle, $\alpha$, the link length, $a$, and the joint offset, $d$.
These parameters are identified by inspection, and are based off the coordinates from and lengths defined in Figure~\ref{dh_params}.
The resulting D-H parameters are presented in Table~\ref{dhparams}.
The parameters are plugged into the generic D-H transformation matrix, see Equation~\ref{dh_matrix}.
This equation transforms positions and rotations from the $i^{th}$ to the $i+1^{th}$ coordinates frames.
\begin{align}
T_{i, i+1} &=
\left[\begin{matrix}
\cos{\left (\phi \right )} & - \cos{\left (\alpha \right )} \sin{\left (\phi \right )} &   \sin{\left (\alpha \right )} \sin{\left (\phi \right )} & a \cos{\left (\phi \right )}\\
\sin{\left (\phi \right )} &   \cos{\left (\alpha \right )} \cos{\left (\phi \right )} & - \sin{\left (\alpha \right )} \cos{\left (\phi \right )} & a \sin{\left (\phi \right )}\\
                         0 &   \sin{\left (\alpha \right )}                            &   \cos{\left (\alpha \right )} & d\\
0 & 0 & 0 & 1
\end{matrix}\right]
\label{dh_matrix}
\end{align}

\begin{table}[h]
\centering
\begin{tabular}{c|*{4}{c}}
\toprule
$i$ & $\theta_i$ & $\alpha_i$ & $a_i$ & $d_i$ \\
\midrule
1 &  90 & 90 &     0 & $d_1$ \\
2 &  90 & 90 &     0 & $d_2$ \\
3 &   0 &  0 & $a_3$ & $d_3$ \\
4 &   0 &  0 & $a_4$ &     0 \\
5 & 180 & 90 &     0 &     0 \\
6 & -90 & 90 &     0 & $d_6$ \\
7 & 180 & 90 &     0 & $d_7$ \\
\bottomrule
\end{tabular}
\caption{The Denavit-Hartenberg parameters for the SSRMS.
These parameters are the joint angle, $\theta$, the link twist angle, $\alpha$, the link length, $a$, and the joint offset, $d$.
These $\theta_i$s give the initial or ``zero-displacement'' configuration, but each $\theta_i$ is modeled as an individual variable below.}
\label{dhparams}
\end{table}

The resulting seven matrices are therefore
\begin{align*}
T_{01} &=
\left[\begin{matrix}\cos{\left (\theta_{1} \right )} & 0 & \sin{\left (\theta_{1} \right )} & 0\\\sin{\left (\theta_{1} \right )} & 0 & - \cos{\left (\theta_{1} \right )} & 0\\0 & 1 & 0 & d_{1}\\0 & 0 & 0 & 1\end{matrix}\right]
&&T_{12} =
\left[\begin{matrix}\cos{\left (\theta_{2} \right )} & 0 & \sin{\left (\theta_{2} \right )} & 0\\\sin{\left (\theta_{2} \right )} & 0 & - \cos{\left (\theta_{2} \right )} & 0\\0 & 1 & 0 & d_{2}\\0 & 0 & 0 & 1\end{matrix}\right] \\
T_{23} &=
\left[\begin{matrix}\cos{\left (\theta_{3} \right )} & - \sin{\left (\theta_{3} \right )} & 0 & a_{3} \cos{\left (\theta_{3} \right )}\\\sin{\left (\theta_{3} \right )} & \cos{\left (\theta_{3} \right )} & 0 & a_{3} \sin{\left (\theta_{3} \right )}\\0 & 0 & 1 & d_{3}\\0 & 0 & 0 & 1\end{matrix}\right]
&&T_{34} =
\left[\begin{matrix}\cos{\left (\theta_{4} \right )} & - \sin{\left (\theta_{4} \right )} & 0 & a_{4} \cos{\left (\theta_{4} \right )}\\\sin{\left (\theta_{4} \right )} & \cos{\left (\theta_{4} \right )} & 0 & a_{4} \sin{\left (\theta_{4} \right )}\\0 & 0 & 1 & 0\\0 & 0 & 0 & 1\end{matrix}\right] \\
T_{45} &=
\left[\begin{matrix}\cos{\left (\theta_{5} \right )} & 0 & \sin{\left (\theta_{5} \right )} & 0\\\sin{\left (\theta_{5} \right )} & 0 & - \cos{\left (\theta_{5} \right )} & 0\\0 & 1 & 0 & 0\\0 & 0 & 0 & 1\end{matrix}\right]
&&T_{56} =
\left[\begin{matrix}\cos{\left (\theta_{6} \right )} & 0 & \sin{\left (\theta_{6} \right )} & 0\\\sin{\left (\theta_{6} \right )} & 0 & - \cos{\left (\theta_{6} \right )} & 0\\0 & 1 & 0 & d_{6}\\0 & 0 & 0 & 1\end{matrix}\right] \\
T_{67} &=
\left[\begin{matrix}\cos{\left (\theta_{7} \right )} & 0 & \sin{\left (\theta_{7} \right )} & 0\\\sin{\left (\theta_{7} \right )} & 0 & - \cos{\left (\theta_{7} \right )} & 0\\0 & 1 & 0 & d_{7}\\0 & 0 & 0 & 1\end{matrix}\right]
\end{align*}

\subsubsection{Direct Kinematics}
Once these seven matrices are defined, it is often desirable to be able to translate directly from the initial coordinate frame to the final end effector frame.
This is easily found by multiplying the successive matrices together to form $T_{07}$, see Equation~\ref{direct}.
Multiplying these matrices together yields
\begin{align}
T_{07} =& T_{01} T_{12} T_{23} T_{34} T_{45} T_{56} T_{67} \label{direct} \\
T_{07}[1, 1] &= u_x =   \left(- s_{1} c_{345} + s_{345} c_{1} c_{2}\right) s_{7} + \left(s_{1} s_{345} c_{6} + s_{2} s_{6} c_{1} + c_{1} c_{2} c_{6} c_{345}\right) c_{7} \nonumber \\
T_{07}[2, 1] &= u_y =   \left(s_{1} s_{345} c_{2} + c_{1} c_{345}\right) s_{7} + \left(s_{1} s_{2} s_{6} + s_{1} c_{2} c_{6} c_{345} - s_{345} c_{1} c_{6}\right) c_{7} \nonumber \\
T_{07}[3, 1] &= u_z =   \left(s_{2} c_{6} c_{345} - s_{6} c_{2}\right) c_{7} + s_{2} s_{7} s_{345} \nonumber \\
T_{07}[4, 1] &=   0 = 0 \nonumber \\
T_{07}[1, 2] &= v_x =   s_{1} s_{6} s_{345} - s_{2} c_{1} c_{6} + s_{6} c_{1} c_{2} c_{345} \nonumber \\
T_{07}[2, 2] &= v_y =   - s_{1} s_{2} c_{6} + s_{1} s_{6} c_{2} c_{345} - s_{6} s_{345} c_{1} \nonumber \\
T_{07}[3, 2] &= v_z =   s_{2} s_{6} c_{345} + c_{2} c_{6} \nonumber \\
T_{07}[4, 2] &=   0 = 0 \nonumber \\
T_{07}[2, 3] &= w_x =   - \left(s_{1} s_{345} c_{2} + c_{1} c_{345}\right) c_{7} + \left(s_{1} s_{2} s_{6} + s_{1} c_{2} c_{6} c_{345} - s_{345} c_{1} c_{6}\right) s_{7} \nonumber \\
T_{07}[1, 3] &= w_y =   \left(s_{1} c_{345} - s_{345} c_{1} c_{2}\right) c_{7} + \left(s_{1} s_{345} c_{6} + s_{2} s_{6} c_{1} + c_{1} c_{2} c_{6} c_{345}\right) s_{7} \nonumber \\
T_{07}[3, 3] &= w_z =   \left(s_{2} c_{6} c_{345} - s_{6} c_{2}\right) s_{7} - s_{2} s_{345} c_{7} \nonumber \\
T_{07}[4, 3] &=   0 = 0 \nonumber \\
T_{07}[1, 4] &= p_x =   a_{3} s_{1} s_{3} + a_{3} c_{1} c_{2} c_{3} + a_{4} s_{1} s_{34} + a_{4} c_{1} c_{2} c_{34} + d_{2} s_{1} + d_{3} s_{2} c_{1} - d_{6} s_{1} c_{345} + d_{6} s_{345} c_{1} c_{2} \nonumber \\
              &\phantom{= a_b =}   + d_{7} s_{1} s_{6} s_{345} - d_{7} s_{2} c_{1} c_{6} + d_{7} s_{6} c_{1} c_{2} c_{345} \nonumber \\
T_{07}[2, 4] &= p_y =   a_{3} s_{1} c_{2} c_{3} - a_{3} s_{3} c_{1} + a_{4} s_{1} c_{2} c_{34} - a_{4} s_{34} c_{1} - d_{2} c_{1} + d_{3} s_{1} s_{2} + d_{6} s_{1} s_{345} c_{2} + d_{6} c_{1} c_{345} \nonumber \\
              &\phantom{= a_b =}   - d_{7} s_{1} s_{2} c_{6} + d_{7} s_{1} s_{6} c_{2} c_{345} - d_{7} s_{6} s_{345} c_{1} \nonumber \\
T_{07}[3, 4] &= p_z =   a_{3} s_{2} c_{3} + a_{4} s_{2} c_{34} + d_{1} - d_{3} c_{2} + d_{6} s_{2} s_{345} + d_{7} s_{2} s_{6} c_{345} + d_{7} c_{2} c_{6} \nonumber \\
T_{07}[4, 4] &=   1 = 1 \nonumber
\end{align}

\subsection{Joint/Shape Matrices}
We can similarly use joint and shape matrices to arrive at these $T$ matrices.
Shape matrices allow for a more general approach compared to D-H matrices, and ``avoid the difficulties that sometimes arise in the use of D-H matrices''~\cite{uicker2013matrix}.
For easier readability, we relabel the joints from $1-7$ to $A-G$.
All of the joints of the SSRMS are revolute.
A general revolute joint, $h$, can be modeled with the joint matrix of
\begin{align*}
\Phi_h \left( \phi_h \right) =
\left[\begin{matrix}
\cos\left( \phi_h \right) & -\sin\left( \phi_h \right) & 0 & 0 \\
\sin\left( \phi_h \right) & \cos\left( \phi_h \right) & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1
\end{matrix}\right]
\end{align*}
We can construct the seven $T$ matrices by
\begin{align}
T_{i,i+1} &= S_{i, j} J_j S_{i+1,j}^{-1} \label{joint_eq} \\
T_{01} &= S_{0A} J_A S_{1A}^{-1} \nonumber \\
T_{12} &= S_{1B} J_B S_{2B}^{-1} \nonumber \\
T_{23} &= S_{2C} J_C S_{3C}^{-1} \nonumber \\
T_{34} &= S_{3D} J_D S_{4D}^{-1} \nonumber \\
T_{45} &= S_{4E} J_E S_{5E}^{-1} \nonumber \\
T_{56} &= S_{5F} J_F S_{6F}^{-1} \nonumber \\
T_{67} &= S_{6G} J_G S_{7G}^{-1} \nonumber
\end{align}
For joints $J_A, J_B, J_C, J_D, J_E, J_F,$ and $J_G$, we also define two shape matrices.
\begin{align*}
\phantom{T_{01}}&
&& S_{0A} = I,
S_{1A} =
\begin{bmatrix*}[c]
1 & 0 & 0 & 0 \\
0 & 0 & 1 & -d_1 \\
0 & -1 & 0 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix*}, \\
S_{1B} &= I,
S_{2B} =
\begin{bmatrix*}[c]
1 & 0 & 0 & 0 \\
0 & 0 & 1 & -d_2 \\
0 & -1 & 0 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix*},
&& S_{2C} = I,
S_{3C} =
\begin{bmatrix*}[c]
1 & 0 & 0 & -a_3 \\
0 & 0 & 1 & -d_3 \\
0 & 1 & 0 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix*}, \\
S_{3D} &= I,
S_{4D} =
\begin{bmatrix*}[c]
1 & 0 & 0 & -a_3 \\
0 & 0 & 1 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix*},
&& S_{4E} = I,
S_{5E} =
\begin{bmatrix*}[c]
1 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & -1 & 0 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix*}, \\
S_{5F} &= I,
S_{6F} =
\begin{bmatrix*}[c]
1 & 0 & 0 & 0 \\
0 & 0 & 1 & -d_6 \\
0 & -1 & 0 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix*},
&& S_{6G} = I,
S_{7G} =
\begin{bmatrix*}[c]
1 & 0 & 0 & 0 \\
0 & 0 & 1 & -d_7 \\
0 & -1 & 0 & 0 \\
0 & 0 & 0 & 1 \\
\end{bmatrix*}
\end{align*}
Multiplying out these shape and joint matrices according toe Equation~\ref{joint_eq} yields the same $T$ matrices as obtained using the Denavit-Hartenberg parameters.

\subsection{Inverse Kinematics}
\subsubsection{Method}
The SSRMS has eight solutions of joint angles for any such given pose~\cite{xu2014analytical}.
In their 2014 paper, Xu et al. show how to to solve for these configurations using a series of flags labeled ``SHOULDER'', ``WRIST'', and ``ELBOW''.
After locking the first rotary joint at a known angle, there are a pair of solutions for the second joint known as the ``SHOULDER'' configuration.
With the first two joints known, it is then possible to solve for the final two joints, giving the ``WRIST'' configuration.
Finally, the middle three joints can be solved for, giving the ``ELBOW'' configuration.

This technique was inspired by a 1984 paper by Lee and Ziegler which used this geometric approach to solve for the inverse kinematics of PUMA robots~\cite{lee1984geometric}.
In their paper, Lee and Ziegler define 4 ``indicators'' (``ARM'', ``ELBOW'', ``WRIST'', and `FLIP'') based off the geometric configuration of the PUMA robot.
These indicators were used to provide consistent solutions for the PUMA robots during movement through their workspace.
Lee and Ziegler presented an algorithmic approach which was programmed to show how their method could be used in practice.
An example of two of these indicators in shown in Figure~\ref{puma}.

For the SSRMS solution presented below, the SHOULDER, ELBOW, and WRIST configuration indicators take on the follow values~\cite{xu2014analytical}
\begin{align*}
\text{SHOULDER}&=\begin{cases}
    +1, & \text{right shoulder}.\\
    -1, & \text{left shoulder}.
\end{cases}\\
\text{ELBOW}&=\begin{cases}
    +1, & \text{outside elbow}.\\
    -1, & \text{inside elbow}.
\end{cases}\\
\text{WRIST}&=\begin{cases}
    +1, & \text{wrist down}.\\
    -1, & \text{wrist up}.
\end{cases}
\end{align*}

\begin{figure}[b!]
\begin{centering}
\includegraphics[width=0.5\textwidth]{puma.jpg}
\caption{Definition of two of the PUMA robotic arm configurations, taken from Lee and Ziegler~\cite{lee1984geometric}.}
\label{puma}
\end{centering}
\end{figure}

\subsubsection{SSRMS Solution}
In general, for a known end effector pose, we can define~\cite{mae225_notes}
\begin{align*}
T_{07} &=
\left[\begin{matrix}
u_x & v_x & w_x & p_x \\
u_y & v_y & w_y & p_y \\
u_z & v_z & w_z & p_z \\
  0 &   0 &   0 &   1 \\
\end{matrix}\right]\\
&= T_{01} T_{12} T_{23} T_{34} T_{45} T_{56} T_{67}
\end{align*}
Premultiplying both sides by $T_{01}^{-1}$ yields,
\begin{align*}
T_{01}^{-1} T_{07} = T_{12} T_{23} T_{34} T_{45} T_{56} T_{67}
\end{align*}
Equating each element $(i,j)$ on both the left and right hand sides yields:
\begin{align}
u_x c_1 + u_y s_1 &= \left(s_{2} s_{6} + c_{2} c_{6} c_{345}\right) c_{7} + s_{7} s_{345} c_{2} \label{eq1} \\
v_x c_1 + v_y s_1 &= - s_{2} c_{6} + s_{6} c_{2} c_{345} \label{eq5} \\
w_x c_1 + w_y s_1 &= \left(s_{2} s_{6} + c_{2} c_{6} c_{345}\right) s_{7} - s_{345} c_{2} c_{7} \label{eq7} \\
p_x c_1 + p_y s_1 &= a_{3} c_{2} c_{3} + a_{4} c_{2} c_{34} + d_{3} s_{2} + d_{6} s_{345} c_{2} - d_{7} s_{2} c_{6} + d_{7} s_{6} c_{2} c_{345} \label{eq3} \\
u_z                 &= \left(s_{2} c_{6} c_{345} - s_{6} c_{2}\right) c_{7} + s_{2} s_{7} s_{345} \label{eq2} \\
v_z                 &= s_{2} s_{6} c_{345} + c_{2} c_{6} \label{eq6} \\
w_z                 &= \left(s_{2} c_{6} c_{345} - s_{6} c_{2}\right) s_{7} - s_{2} s_{345} c_{7} \label{eq8} \\
- d_{1} + p_z       &= a_{3} s_{2} c_{3} + a_{4} s_{2} c_{34} - d_{3} c_{2} + d_{6} s_{2} s_{345} + d_{7} s_{2} s_{6} c_{345} + d_{7} c_{2} c_{6} \label{eq4} \\
u_x s_1 - u_y c_1 &= - s_{7} c_{345} + s_{345} c_{6} c_{7} \label{th51}\\
v_x s_1 - v_y c_1 &= s_{6} s_{345} \label{th53} \\
w_x s_1 - w_y c_1 &= s_{7} s_{345} c_{6} + c_{7} c_{345} \label{th52} \\
p_x s_1 - p_y c_1 &= a_{3} s_{3} + a_{4} s_{34} + d_{2} - d_{6} c_{345} + d_{7} s_{6} s_{345} \\
0                     &= 0 \\
0                     &= 0 \\
0                     &= 0 \\
1                     &= 1
\end{align}
where we have defined $s_i = \sin{i}, c_i = \cos{i}, s_{ij} = \sin{\left(i+j\right)}, c_{ij} = \cos{\left(i+j\right)}, s_{ijk} = \sin{\left(i+j+k\right)}$ and $c_{ijk} = \cos{\left(i+j+k\right)}$.
Manipulating the equations, we take $\left(Eq.~\ref{eq1} \right) s_2 - \left(Eq.~\ref{eq2} \right) c_2$ and simplify, producing
\begin{align}
\left(u_x c_1 + u_y s_1\right) s_2 - u_z c_2 &= s_{6} c_{7} \label{eqc3}
\end{align}
Similarly, we can do $\left(Eq.~\ref{eq3} \right) s_2-\left(Eq.~\ref{eq4}\right) c_2$ and simplify, which results in
\begin{align}
\left(p_x c_1 + p_y s_1 \right) s_2 - \left(- d_{1} + p_z \right) c_2 &= d_3 - c_6 d_7 \label{eqc1}
\end{align}
We can also subtract $\left(Eq.~\ref{eq6} \right) c_2 - \left(Eq.~\ref{eq5} \right) s_2$
\begin{align}
v_z c_2 - \left( v_x c_1 + v_y s_1 \right) s_2 &= c_{6} \label{eqc2}
\end{align}
Finally, we can also subtract $\left(Eq.~\ref{eq7} \right) s_2 - \left(Eq.~\ref{eq8} \right) c_2$
\begin{align}
\left(w_x c_1 + w_y s_1\right) s_2 - w_z c_2 &= s_{6} s_{7} \label{eqc4}
\end{align}
Rearranging Equations~\ref{eqc1} and \ref{eqc2} to be equal to $c_6$ and equating the two yields
\begin{align}
-d_3 &= \left( \left( v_x d_7 - p_x \right) c_1 + \left( v_y d_7 - p_y \right) s_1 \right) s_2 + \left(-v_z d_7 - d_{1} + p_z \right) c_2
\end{align}
Locking the shoulder roll angle to a known angle, $\boxed{\theta_1 = \beta}$, we can solve for $\theta_2$,
\begin{align}
\boxed{\theta_2 = \mbox{SHOULDER} \cdot \acos \left( \dfrac{d_3}{\sqrt{h_1^2 + q_1^2}} \right) + \atantwo(q_1,h_1)}
\end{align}
where
\begin{align}
h_1 &= \left(-v_z d_7 - d_{1} + p_z \right) \\
q_1 &= \left( \left( v_x d_7 - p_x \right) c_{\beta} + \left( v_y d_7 - p_y \right) s_{\beta} \right)
\end{align}
With $\theta_1$ and $\theta_2$ now known, $\theta_6$ can be solved using Equation~\ref{eqc2},
\begin{align}
\boxed{\theta_6 = \mbox{WRIST} \cdot \acos \left(v_z c_2 - \left( v_x c_1 + v_y s_1 \right) s_2 \right)}
\end{align}
And we can then combine Equations~\ref{eqc3} and~\ref{eqc4}, yielding
\begin{align}
\boxed{\theta_7 = \atantwo \left( \dfrac{\left(u_x c_1 + u_y s_1\right) s_2 - u_z c_2}{s_6},
                                  \dfrac{\left(w_x c_1 + w_y s_1\right) s_2 - w_z c_2}{s_6}\right)}
\end{align}
With the shoulder and wrist joints resolved, we can now solve for the middle joints.
We now take
\begin{align*}
\left(T_{12}^{-1} \right) \left(T_{17}\right) \left(T_{67}^{-1}\right) \left(T_{56}^{-1}\right) = \left(T_{23}\right) \left(T_{34}\right) \left(T_{45}\right)
\end{align*}
Taking the left and right hand side $\left(1, 4\right)$ and $\left(2, 4 \right)$ elements from the resulting matrix yields
\begin{align}
a_{3} c_{3} + a_{4} c_{34} &= d_{6} \left(w_z s_{2} + c_{2}\left(w_x c_{1} + w_y s_{1}\right) \right) c_{7} \nonumber \\
                           &\phantom{=} - d_{6} \left(u_z s_{2} + c_{2}\left(u_x c_{1} + u_y s_{1} \right) \right) s_{7}  \nonumber \\
                           &\phantom{=} - d_{7} \left(v_z s_{2} + c_{2}\left(v_x c_{1} + v_y s_{1} \right) \right) \nonumber \\
                           &\phantom{=}+ \left(- d_{1} + p_z\right) s_{2} + c_{2}\left(p_x c_{1} + p_y s_{1}\right) \label{mj1} \\
a_{3} s_{3} + a_{4} s_{34} &= - d_{2} + d_{6} \left(w_x s_{1} - w_y c_{1}\right) c_{7} - d_{6} \left(u_x s_{1} - u_y c_{1}\right) s_{7} \nonumber \\
                           &\phantom{=} - d_{7} \left(v_x s_{1} - v_y c_{1}\right) + p_x s_{1} - p_y c_{1} \label{mj2}
\end{align}
$\theta_4$ is then solved by combining the above two equations, resulting in
\begin{align}
\boxed{\theta_4 = \mbox{ELBOW} \cdot \acos \left( \dfrac{X^2 + Y^2 - a_3^2 - a_4^2}{2 a_3 a_4} \right)}
\end{align}
where
\begin{align*}
X &= d_{6} \left( \left(w_z s_{2} + c_{2}\left(w_x c_{1} + w_y s_{1}\right) \right) c_{7} - \left(u_z s_{2} + c_{2}\left(u_x c_{1} + u_y s_{1} \right) \right) s_{7} \right) \nonumber \\
  &\phantom{=}- d_{7} \left(v_z s_{2} + c_{2}\left(v_x c_{1} + v_y s_{1} \right) \right) + \left(- d_{1} + p_z\right) s_{2} + c_{2}\left(p_x c_{1} + p_y s_{1}\right) \\
Y &= - d_{2} + d_{6} \left(w_x s_{1} - w_y c_{1}\right) c_{7} - d_{6} \left(u_x s_{1} - u_y c_{1}\right) s_{7} - d_{7} \left(v_x s_{1} - v_y c_{1}\right) + p_x s_{1} - p_y c_{1}
\end{align*}
Substituting the solution into $\theta_4$ and Equations~\ref{mj1} and~\ref{mj2} and combining yields
\begin{align*}
\boxed{\theta_3 = \atantwo \left(Y \left( a_3 + a_4 c_4 \right) - X a_4 s_4, X \left(a_3 + a_4 c_4 \right) + Y a_4 s_4 \right)}
\end{align*}
Subtracting $(Eq.~\ref{th52}) c_7$ and $(Eq.~\ref{th51}) s_7$ yields
\begin{align*}
c_{345} &= \left(w_x s_1 - w_y c_1\right) c_7 - \left(u_x s_1 - u_y c_1 \right) s_7
\end{align*}
And from Equation~\ref{th53} we have
\begin{align*}
s_{345} = \dfrac{v_x s_1 - v_y c_1 }{s_{6}}
\end{align*}
which we can combine to solve for the last joint
\begin{align*}
\theta_5 &= \left(\theta_3 + \theta_4 + \theta_5 \right) - \left(\theta_3 + \theta_4 \right) \\
\alignedbox{\theta_5}{=\atantwo \left(s_{345}, c_{345} \right) - \left(\theta_3 + \theta_4 \right)}
\end{align*}

\subsection{Numerical Example}
For practical purposes, the link length and offset values can be set to
\begin{align*}
a_{3} = 2.30, a_{4} = 2.30, d_{1} = 0.65, d_{2} = 0.30, d_{3} = 0.90, d_{6} = 0.30, d_{7} = 0.65
\end{align*}
Note that $a_3=a_4, d_1=d_7, \text{and } d_2=d_6$, as the arm is symmetric.
As an example, plugging in these values and the initial angles given in Table~\ref{dhparams} into Equation~\ref{direct} yields
\begin{align*}
T_{07} &=
\left[\begin{matrix}
0 & 0 & 1 & 0.6 \\
1 & 0 & 0 & 0.9 \\
0 & 1 & 0 & 5.9 \\
0 & 0 & 0 &   1 \\
\end{matrix}\right] \\
\end{align*}
As another example, given the end effector pose
\begin{align*}
T_{07} &=
\left[\begin{matrix}
0.8021 & 0.1217 & 0.5846 & 2.4790 \\
-0.5859 & 0.3495 & 0.7311 & -2.4734 \\
-0.1154 & 0.9290 & 0.3517 & -0.4927 \\
0 & 0 & 0 & 1
\end{matrix}\right]
\end{align*}
and locking the first joint variable $\theta_1 = \beta = 60^\circ$, we can solve for the 8 possible configurations of the arm, see Table~\ref{ik_res}.
The equations used to solve for these values are taken from above, and the code used to generate these results are in the Appendex.
\begin{table}[h]
\centering
\begin{tabular}{*{10}{r}}
\toprule
S & E & W & $\theta_1$ & $\theta_2$ & $\theta_3$ & $\theta_4$ & $\theta_5$ & $\theta_6$ & $\theta_7$ \\
\midrule
 1 &  1 &  1 & 60.000 &  -20.268   &  64.074 &   79.722 & -149.770 &  138.205 & -77.426 \\
 1 &  1 & -1 & 60.000 &  -20.268   &  58.153 &   99.444 &   16.428 & -138.205 & 102.573 \\
 1 & -1 &  1 & 60.000 &  -20.268   & 143.797 &  -79.722 &  -70.048 &  138.205 & -77.426 \\
-1 &  1 &  1 & 60.000 & -109.087   &  35.576 &   79.140 & -119.938 &   49.659 & -85.275 \\
 1 & -1 & -1 & 60.000 &  -20.268   & 157.598 &  -99.444 &  115.872 & -138.205 & 102.573 \\
-1 &  1 & -1 & 60.000 & -109.087   &  23.189 &  100.025 &   51.565 &  -49.659 &  94.724 \\
-1 & -1 &  1 & 60.000 & -109.087   & 114.717 &  -79.140 &  -40.797 &   49.659 & -85.275 \\
-1 & -1 & -1 & 60.000 & -109.087   & 123.214 & -100.025 &  151.590 &  -49.659 &  94.724 \\
\bottomrule
\end{tabular}
\caption{The eight possible configurations for locking the first joint, where S, E, and W stand for ``SHOULDER'', ``ELBOW'', and ``WRIST'', respectively.}
\label{ik_res}
\end{table}

\section{Differential Kinematic Analysis}
\subsection{Method 1: Kinematic Jacobian}
The first Jacobian is based of a kinematic approach.
Where $\hat{z}_i$ is taken from the last column of $T_{0i}$, and can be defined~\cite{mae225_notes}
\begin{align*}
T_{0i} &=
\left[\begin{matrix}
  & \du{\Theta}_i &   & \vdots & a_i \\
  & \hdots   &   &        & \hdots \\
0 &        0 & 0 & \vdots & 1
\end{matrix}\right] \\
{\Theta}_i &=
\left[\begin{matrix}
& & \\
x_i & y_i & z_i \\
& &
\end{matrix}\right] \\
\hat{z}_i &= \left( \prod_{i=0}^n {\Theta}_i \right) z_i
\end{align*}
and $\vec{r}_i$ is defined
\begin{align*}
\vec{r}_i = \sum_{i=0}^n \vec{a}_i
\end{align*}
With these definitions, we can find the Jacobian via
\begin{align*}
\dot{\vec{P}} &= \sum_{i=0}^{n} \left( \hat{z}_i \times \vec{r}_i \right) \dot{\theta}_i \\
\vec{w} &= \sum_{i=0}^{n} \dot{\theta}_i \hat{z}_i \\
{J}_K \dot{q} &=
\left[\begin{matrix}
\underline{\dot{P}} \\
\underline{\vec{w}}
\end{matrix}\right] \\
\left[\begin{matrix}
\hat{z}_1 \times \vec{r}_1 & \hat{z}_2 \times \vec{r}_2 & \cdots & \hat{z}_7 \times \vec{r}_7 \\
\hat{z}_1 & \hat{z}_2 & \cdots & \hat{z}_7
\end{matrix}\right]
\left[\begin{matrix}
\dot{\theta}_1 \\
\dot{\theta}_2 \\
\vdots \\
\dot{\theta}_7 \\
\end{matrix}\right]
&=
\left[\begin{matrix}
\underline{\dot{P}}_{EE} \\
\underline{w}_{EE} \\
\end{matrix}\right] \\
\end{align*}
The results of these equations yield in the kinematic Jacobian,
\begin{align*}
J_{11} &= - a_{3} s_{1} c_{2} c_{3} + a_{3} s_{3} c_{1} - a_{4} s_{1} c_{2} c_{34} + a_{4} s_{34} c_{1} + d_{2} c_{1} - d_{3} s_{1} s_{2} \\
       &\phantom{= }- d_{6} s_{1} s_{345} c_{2} - d_{6} c_{1} c_{345} + d_{7} s_{1} s_{2} c_{6} - d_{7} s_{1} s_{6} c_{2} c_{345} + d_{7} s_{6} s_{345} c_{1} \\
J_{21} &= a_{3} s_{1} s_{3} + a_{3} c_{1} c_{2} c_{3} + a_{4} s_{1} s_{34} + a_{4} c_{1} c_{2} c_{34} + d_{2} s_{1} + d_{3} s_{2} c_{1} \\
       &\phantom{= }- d_{6} s_{1} c_{345} + d_{6} s_{345} c_{1} c_{2} + d_{7} s_{1} s_{6} s_{345} - d_{7} s_{2} c_{1} c_{6} + d_{7} s_{6} c_{1} c_{2} c_{345} \\
J_{31} &= 0 \\
J_{41} &= 0 \\
J_{51} &= 0 \\
J_{61} &= 1 \\
\\
J_{12} &= - \left(a_{3} s_{2} c_{3} + a_{4} s_{2} c_{34} - d_{3} c_{2} + d_{6} s_{2} s_{345} + d_{7} s_{2} s_{6} c_{345} + d_{7} c_{2} c_{6}\right) c_{1} \\
J_{22} &= - \left(a_{3} s_{2} c_{3} + a_{4} s_{2} c_{34} - d_{3} c_{2} + d_{6} s_{2} s_{345} + d_{7} s_{2} s_{6} c_{345} + d_{7} c_{2} c_{6}\right) s_{1} \\
J_{32} &= a_{3} c_{2} c_{3} + a_{4} c_{2} c_{34} + d_{3} s_{2} + d_{6} s_{345} c_{2} - d_{7} s_{2} c_{6} + d_{7} s_{6} c_{2} c_{345} \\
J_{42} &= s_{1} \\
J_{52} &= - c_{1} \\
J_{62} &= 0
\end{align*}
\begin{align*}
J_{13} &= a_{3} s_{1} c_{3} - a_{3} s_{3} c_{1} c_{2} + a_{4} s_{1} c_{34} - a_{4} s_{34} c_{1} c_{2} + d_{6} s_{1} s_{345} \\
       &\phantom{= }+ d_{6} c_{1} c_{2} c_{345} + d_{7} s_{1} s_{6} c_{345} - d_{7} s_{6} s_{345} c_{1} c_{2} \\
J_{23} &= - a_{3} s_{1} s_{3} c_{2} - a_{3} c_{1} c_{3} - a_{4} s_{1} s_{34} c_{2} - a_{4} c_{1} c_{34} + d_{6} s_{1} c_{2} c_{345} \\
       &\phantom{= }- d_{6} s_{345} c_{1} - d_{7} s_{1} s_{6} s_{345} c_{2} - d_{7} s_{6} c_{1} c_{345} \\
J_{33} &= \left(- a_{3} s_{3} - a_{4} s_{34} + d_{6} c_{345} - d_{7} s_{6} s_{345}\right) s_{2} \\
J_{43} &= s_{2} c_{1} \\
J_{53} &= s_{1} s_{2} \\
J_{63} &= - c_{2} \\
\\
J_{14} &= a_{4} s_{1} c_{34} - a_{4} s_{34} c_{1} c_{2} + d_{6} s_{1} s_{345} + d_{6} c_{1} c_{2} c_{345} + d_{7} s_{1} s_{6} c_{345} - d_{7} s_{6} s_{345} c_{1} c_{2} \\
J_{24} &= - a_{4} s_{1} s_{34} c_{2} - a_{4} c_{1} c_{34} + d_{6} s_{1} c_{2} c_{345} - d_{6} s_{345} c_{1} - d_{7} s_{1} s_{6} s_{345} c_{2} - d_{7} s_{6} c_{1} c_{345} \\
J_{34} &= \left(- a_{4} s_{34} + d_{6} c_{345} - d_{7} s_{6} s_{345}\right) s_{2} \\
J_{44} &= s_{2} c_{1} \\
J_{54} &= s_{1} s_{2} \\
J_{64} &= - c_{2} \\
\\
J_{15} &= d_{6} s_{1} s_{345} + d_{6} c_{1} c_{2} c_{345} + d_{7} s_{1} s_{6} c_{345} - d_{7} s_{6} s_{345} c_{1} c_{2} \\
J_{25} &= d_{6} s_{1} c_{2} c_{345} - d_{6} s_{345} c_{1} - d_{7} s_{1} s_{6} s_{345} c_{2} - d_{7} s_{6} c_{1} c_{345} \\
J_{35} &= \left(d_{6} c_{345} - d_{7} s_{6} s_{345}\right) s_{2} \\
J_{45} &= s_{2} c_{1} \\
J_{55} &= s_{1} s_{2} \\
J_{65} &= - c_{2} \\
\\
J_{16} &= d_{7} \left(s_{1} s_{345} c_{6} + s_{2} s_{6} c_{1} + c_{1} c_{2} c_{6} c_{345}\right) \\
J_{26} &= d_{7} \left(s_{1} s_{2} s_{6} + s_{1} c_{2} c_{6} c_{345} - s_{345} c_{1} c_{6}\right) \\
J_{36} &= d_{7} \left(s_{2} c_{6} c_{345} - s_{6} c_{2}\right) \\
J_{46} &= - s_{1} c_{345} + s_{345} c_{1} c_{2} \\
J_{56} &= s_{1} s_{345} c_{2} + c_{1} c_{345} \\
J_{66} &= s_{2} s_{345} \\
\\
J_{17} &= 0 \\
J_{27} &= 0 \\
J_{37} &= 0 \\
J_{47} &= \left(s_{1} s_{345} + c_{1} c_{2} c_{345}\right) s_{6} - s_{2} c_{1} c_{6} \\
J_{57} &= \left(s_{1} c_{2} c_{345} - s_{345} c_{1}\right) s_{6} - s_{1} s_{2} c_{6} \\
J_{67} &= s_{2} s_{6} c_{345} + c_{2} c_{6} \\
\end{align*}

\subsection{Method 2: Geometric Jacobian}
The geometric Jacobian is formed from a linearized form of the kinematic equations~\cite{mae225_notes}.
We first form our $^i D$ matrices from
\begin{align*}
^i D = T_{i-1} Q_i T_{i-1}^{-1}
\end{align*}
And $T_{0}= {I}, T_{i} = \prod_0^n A_n,$ where $A_n$ are the matrices formed by the D-H parameters.
Where, as all our joints are revolute, the derivative operator matrix is
\begin{align*}
Q &=
\left[\begin{matrix}
    0 & -1 & 0 & 0 \\
    1 &  0 & 0 & 0 \\
    0 &  0 & 0 & 0 \\
    0 &  0 & 0 & 0 \\
\end{matrix}\right]
\end{align*}
Selecting elements from these $^i D$ matrices, we form the Jacobian via
\begin{align*}
J_G &=
\left[\begin{matrix}
^0D_{14} & ^1D_{14} & ^2D_{14} & ^3D_{14} & ^4D_{14} & ^5D_{14} & ^6D_{14} \\
^0D_{24} & ^1D_{24} & ^2D_{24} & ^3D_{24} & ^4D_{24} & ^5D_{24} & ^6D_{24} \\
^0D_{34} & ^1D_{34} & ^2D_{34} & ^3D_{34} & ^4D_{34} & ^5D_{34} & ^6D_{34} \\
^0D_{32} & ^1D_{32} & ^2D_{32} & ^3D_{32} & ^4D_{32} & ^5D_{32} & ^6D_{32} \\
^0D_{13} & ^1D_{13} & ^2D_{13} & ^3D_{13} & ^4D_{13} & ^5D_{13} & ^6D_{13} \\
^0D_{21} & ^1D_{21} & ^2D_{21} & ^3D_{21} & ^4D_{21} & ^5D_{21} & ^6D_{21} \\
\end{matrix}\right]
\end{align*}
And
\begin{align*}
\dot{x} &= J_G \dot{q} \\
\left[\begin{matrix}
\mu_x \\
\mu_y \\
\mu_z \\
\omega_x \\
\omega_y \\
\omega_z \\
\end{matrix}\right]
&=
\left[\begin{matrix}
^0D_{14} & ^1D_{14} & ^2D_{14} & ^3D_{14} & ^4D_{14} & ^5D_{14} & ^6D_{14} \\
^0D_{24} & ^1D_{24} & ^2D_{24} & ^3D_{24} & ^4D_{24} & ^5D_{24} & ^6D_{24} \\
^0D_{34} & ^1D_{34} & ^2D_{34} & ^3D_{34} & ^4D_{34} & ^5D_{34} & ^6D_{34} \\
^0D_{32} & ^1D_{32} & ^2D_{32} & ^3D_{32} & ^4D_{32} & ^5D_{32} & ^6D_{32} \\
^0D_{13} & ^1D_{13} & ^2D_{13} & ^3D_{13} & ^4D_{13} & ^5D_{13} & ^6D_{13} \\
^0D_{21} & ^1D_{21} & ^2D_{21} & ^3D_{21} & ^4D_{21} & ^5D_{21} & ^6D_{21} \\
\end{matrix}\right]
\left[\begin{matrix}
\dot{\theta}_1 \\
\dot{\theta}_2 \\
\dot{\theta}_3 \\
\dot{\theta}_4 \\
\dot{\theta}_5 \\
\dot{\theta}_6 \\
\dot{\theta}_7 \\
\end{matrix}\right]
\end{align*}
Solving for these $^i D$ matrices and selecting the identified elements results in
\begin{align*}
J_{11} &= 0 && J_{12} = d_{1} c_{1}  &&& J_{13} = &&&& - d_{1} s_{1} s_{2} + d_{2} c_{1} c_{2} \\
J_{21} &= 0 && J_{22} = d_{1} s_{1}  &&& J_{23} = &&&& d_{1} s_{2} c_{1} + d_{2} s_{1} c_{2} \\
J_{31} &= 0 && J_{32} = 0            &&& J_{33} = &&&& d_{2} s_{2} \\
J_{41} &= 0 && J_{42} = s_{1}        &&& J_{43} = &&&& s_{2} c_{1} \\
J_{51} &= 0 && J_{52} = - c_{1}      &&& J_{53} = &&&& s_{1} s_{2} \\
J_{61} &= 1 && J_{62} = 0            &&& J_{63} = &&&& - c_{2} \\
\end{align*}

\begin{align*}
J_{14} &= - a_{3} s_{1} c_{3} + a_{3} s_{3} c_{1} c_{2} - d_{1} s_{1} s_{2} + d_{2} c_{1} c_{2} \\
J_{24} &= a_{3} s_{1} s_{3} c_{2} + a_{3} c_{1} c_{3} + d_{1} s_{2} c_{1} + d_{2} s_{1} c_{2} \\
J_{34} &= \left(a_{3} s_{3} + d_{2}\right) s_{2} \\
J_{44} &= s_{2} c_{1} \\
J_{54} &= s_{1} s_{2} \\
J_{64} &= - c_{2} \\
\\
J_{15} &= - a_{3} s_{1} c_{3} + a_{3} s_{3} c_{1} c_{2} - a_{4} s_{1} c_{34} + a_{4} s_{34} c_{1} c_{2} - d_{1} s_{1} s_{2} + d_{2} c_{1} c_{2} \\
J_{25} &= a_{3} s_{1} s_{3} c_{2} + a_{3} c_{1} c_{3} + a_{4} s_{1} s_{34} c_{2} + a_{4} c_{1} c_{34} + d_{1} s_{2} c_{1} + d_{2} s_{1} c_{2} \\
J_{35} &= \left(a_{3} s_{3} + a_{4} s_{34} + d_{2}\right) s_{2} \\
J_{45} &= s_{2} c_{1} \\
J_{55} &= s_{1} s_{2} \\
J_{65} &= - c_{2} \\
\\
J_{16} &= - \left(d_{1} c_{2} - d_{3}\right) \left(s_{1} s_{345} + c_{1} c_{2} c_{345}\right) - \left(a_{3} c_{45} + a_{4} c_{5} + d_{1} s_{2} c_{345} + d_{2} s_{345}\right) s_{2} c_{1} \\
J_{26} &= - \left(d_{1} c_{2} - d_{3}\right) \left(s_{1} c_{2} c_{345} - s_{345} c_{1}\right) - \left(a_{3} c_{45} + a_{4} c_{5} + d_{1} s_{2} c_{345} + d_{2} s_{345}\right) s_{1} s_{2} \\
J_{36} &= a_{3} c_{2} c_{45} + a_{4} c_{2} c_{5} + d_{2} s_{345} c_{2} + d_{3} s_{2} c_{345} \\
J_{46} &= - s_{1} c_{345} + s_{345} c_{1} c_{2} \\
J_{56} &= s_{1} s_{345} c_{2} + c_{1} c_{345} \\
J_{66} &= s_{2} s_{345} \\
\\
J_{17} &= \left(\left(s_{1} s_{345} + c_{1} c_{2} c_{345}\right) c_{6} + s_{2} s_{6} c_{1}\right) \left(a_{3} s_{45} + a_{4} s_{5} + d_{1} s_{2} s_{345} - d_{2} c_{345} + d_{6}\right) \\
       &\phantom{=}+ \left(s_{1} c_{345} - s_{345} c_{1} c_{2}\right) \left(a_{3} c_{6} c_{45} + a_{4} c_{5} c_{6} + d_{1} s_{2} c_{6} c_{345} - d_{1} s_{6} c_{2} + d_{2} s_{345} c_{6} + d_{3} s_{6}\right) \\
J_{27} &= \left(\left(s_{1} c_{2} c_{345} - s_{345} c_{1}\right) c_{6} + s_{1} s_{2} s_{6}\right) \left(a_{3} s_{45} + a_{4} s_{5} + d_{1} s_{2} s_{345} - d_{2} c_{345} + d_{6}\right) \\
       &\phantom{=}- \left(s_{1} s_{345} c_{2} + c_{1} c_{345}\right) \left(a_{3} c_{6} c_{45} + a_{4} c_{5} c_{6} + d_{1} s_{2} c_{6} c_{345} - d_{1} s_{6} c_{2} + d_{2} s_{345} c_{6} + d_{3} s_{6}\right) \\
J_{37} &= \left(s_{2} c_{6} c_{345} - s_{6} c_{2}\right) \left(a_{3} s_{45} + a_{4} s_{5} + d_{1} s_{2} s_{345} - d_{2} c_{345} + d_{6}\right) - \\
       &\phantom{=}\left(a_{3} c_{6} c_{45} + a_{4} c_{5} c_{6} + d_{1} s_{2} c_{6} c_{345} - d_{1} s_{6} c_{2} + d_{2} s_{345} c_{6} + d_{3} s_{6}\right) s_{2} s_{345} \\
J_{47} &= s_{1} s_{6} s_{345} - s_{2} c_{1} c_{6} + s_{6} c_{1} c_{2} c_{345} \\
J_{57} &= - s_{1} s_{2} c_{6} + s_{1} s_{6} c_{2} c_{345} - s_{6} s_{345} c_{1} \\
J_{67} &= s_{2} s_{6} c_{345} + c_{2} c_{6} \\
\end{align*}

\clearpage
\section{Conclusions}
In this report we have completed a kinematic analysis of the Space Station Robotic Manipulator with a locked shoulder roll joint.
Transformation matrices were found using both Denavit-Hartenberg parameters and shape matrices.
The direct kinematic solution was identified using the seven transformation matrices.
The inverse kinematic solution found by Xu et al. was verified and several inaccuracies were fixed~\cite{xu2014analytical}.
Using the resulting inverse kinematic solution along with three configuration indicators, a Python program was written to generate eight solutions for an example pose, matching the solution found by Xu et al.

A differential kinematic analysis was conducted, resulting in two Jacobians.
The kinematic Jacobian, $J_K$, was generated using $\hat{z}$ and $\vec{r}$ derived from the Denavit-Hartenberg matrices.
A geometric Jacobian, $J_G$, was calculated using a different approach involving derivative matrices.
A symbolic Python program was written to calculate and compare the numerical efficiency of these two Jacobians.
$J_K$ required a total of 4833 operations per calculation, or
\begin{verbatim}
269*ADD + 1210*COS + 1754*MUL + 100*NEG + 1106*SIN + 394*SUB
\end{verbatim}
while $J_G$ required a total of 1138 operations per calculation, or
\begin{verbatim}
207*ADD + 225*COS + 351*MUL + 33*NEG + 4*POW + 207*SIN + 111*SUB
\end{verbatim}
Based off this simple analysis, it appears that the geometric Jacobian technique produced a more efficient Jacobian in this case.

% \nocite{*}
\bibliography{bib}
\bibliographystyle{plain}

\clearpage
\appendix
\section{Appendix: Code}
To confirm that the algorithms written here were correct, I used the Stanford Arm examples in class.
I verified that the results produced with the Stanford Arm D-H parameters were correct according the results presented in lecture\footnote{Note that the Stanford Arm D-H parameters presented on 3/6 are different than those presented on 3/13.
On 3/6 the Stanford Arm had $d_1=0$.}.
\lstinputlisting[language=Python]{analysis.py}

\end{document}


\documentclass[a4paper]{jpconf}
\usepackage{graphicx}
\usepackage{subfig}
\begin{document}
\title{von Neumann - Wigner Darboux deformed truncated oscillator.}

\author{L\' opez Mej\' ia L and Fern\' andez-Garc\' ia N}

\address{Instituto Polit\' ecnico Nacional, UPIITA, Av. I.P.N. 2580, Col. La Laguna Ticom\' an, 07360 M\' exico
City, Mexico.}

\ead{llopezm1808@alumno.ipn.mx}

\begin{abstract}
Starting from a radial truncated harmonic oscillator with zero angular momentum, the well known Darboux transformation is used for constructing a von Neumann - Wigner potential type. The method consists in using as a feed function one solution in the continuous regime for implementing a degenerated version of the second order Darboux transformation. After the continuity of the solutions is guaranteed, it is shown that the resulting system, in addition to the scattering and conventional bound states, contains a square integrable wave function associated to one energy eigenvalue belonging to the continuous part of the spectrum, which is justly the eigenvalue corresponding to the transformation function.

\end{abstract}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Introduction.}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

In 1929, von Neumann and Wigner proposed a method to construct a potential that could admit a square integrable solution in the continuous spectrum regime \cite{vNW}; nevertheless, the resulting potential has an oscillatory behavior that goes to zero as $1/r$, which, in principle, does not have a direct correspondence with the behavior of any physical system. In addition, the method has the limitation that only the solution corresponding to the bound state in the continuum can be analytically known, the rest of the solutions would have to be obtained by directly solving the Schr\" odinger equation. For that reasons, at those times, these kind of potentials were considered simply as toy models that could not  occur in nature. However, according to a relatively recent works, the possible existence of such systems has been explored with new techniques in a lot of classical and quantum contexts that involves waves propagation or even in the growing of semiconductor heterostructures by molecular bean epitaxy \cite{Stillinger,Anzor,Stahlhofen,Nature,Pappademos,Mondragon,Nico1,Nico2,Capasso}.\\
The Darboux transformation, also known in the quantum mechanics context as factorization method or supersymmetric quantum mechanics, is a powerful mathematical tool for constructing solutions of the Schr\" odinger equation starting from a system whose solution is known \cite{Witten,Mielnik,Darboux}. This transformation has been widely used in quantum mechanics for constructing isospectral or quasi-isospectral Hamiltonians of well known systems like harmonic oscillator, the hydrogen atom, to name a few (see for example \cite{David,Oscar} and references therein), it has even been used to construct non-Hermitian Hamiltonians with a purely real spectrum \cite{Zurika,Nico3}.\\
In this work, a degenerated version of the  second order Darboux transformation is implemented on the truncated radial harmonic oscillator with zero angular momentum for constructing a von Neumann - Winger type potential.  The scattering and bound states of the deformed system are obtained and the condition for the existence of the bound state in the continuum is established.\\
In section 2 we present a short description of the von Neumann - Wigner method for constructing bound states in the continuum. Section 3 presents how the Darboux transformation operates. In section 4 the general solution for the truncated radial oscillator is presented. In sections 5 and 6 the degenerated version of the Darboux transformation is used for deforming the starting system (truncated radial harmonic oscillator) and the condition for the existence of the bound state in the continuum is stablished. Finally, in section 6, we finish the paper with some concluding remarks.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{The von Neumann - Wigner type potentials.}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

In 1929, unlike what is usually done, von Neumann and Wigner investigated an alternative mechanism to obtain information from the stationary Schr\" odinger equation \cite{vNW,Stillinger}: instead of introducing an interaction potential and  looking for the corresponding eigenvalues and eigenfunctions, they proposed the existence of a square integrable solution associated with an eigenvalue in the continuous regime,  such that the task was to find the kind of potentials which fulfills that property. Bellow, a brief description of the method is presented.\\
Let us write the stationary radial Schr\" odinger equation as follows (in appropriate units and with angular momentum $l=0$):

\begin{equation}
V(r)=E+\frac{1}{2}\frac{\nabla^2\psi(r)}{\psi(r)}.\label{vNW-V0}
\end{equation}

The main idea of the method is to assume the existence of a solution which can be written as the product of a free particle solution and a modulation function $f(r)$, that is,

\begin{equation}
\psi(r)=f(r)\,\frac{\sin{kr}}{kr},\label{vNW-Psi0}
\end{equation}
with $E=k^2$. The substitution of (\ref{vNW-Psi0}) into (\ref{vNW-V0}) leads to the next expression for the potential in terms of $f(r)$

\begin{equation}
V(r)= k \cot{kr}\,\frac{f'(r)}{f(r)}+\frac{1}{2}\frac{f''(r)}{f(r)}, \quad {\rm where}\quad '\equiv \frac{d}{dr}.\label{vNW-V1}
\end{equation}

So we have to look for an appropriate function $f(r)$ that, on the one hand, guarantees that the potential is free of singularities and, on the other, the wave function $\psi(r)$ (associated with the eigenvalue $E=k^2$) is square integrable.
In order to obtain a potential free of singularities, the zeros of $f(r)$ and the product $f(r) \sin{kr}$ must be compensated with zeros, at least of the same order, of $f''(r)$ and $f'(r)$, respectively. With this in mind, von Neumann and Wigner founded the next form for the modulation function \cite{vNW}:

\begin{equation}
f(r)=\frac{1}{A^2+[2kr-\sin{2kr}]^2},\label{vNW-f}
\end{equation}

\begin{figure}
\begin{center}
\includegraphics[scale=0.7]{vNW-Figure.eps}
\end{center}
\caption{\label{vNW-Figure} The von Neumann - Wigner potential (dashed line) and the corresponding bound state in the continuum (solid line) for $k=1$ and $A=1$.}
\end{figure}
where A is a nonzero real constant. The Figure \ref{vNW-Figure} shows the von Neumann - Wigner potential and its corresponding bound state in the continuum for $E=k^2=1$ and the parameter $A=1$, which are obtained substituting the function $f(r)$ into (\ref{vNW-Psi0}) and (\ref{vNW-V1}). The possibilities for the function $f(r)$ are not limited to that presented by von Neumann and Wigner (see for example \cite{Stillinger}), but all of them have an asymptotic oscillatory behavior given by \cite{Stahlhofen}:

\begin{equation}
\lim_{r\rightarrow\infty}V(r) \rightarrow a\,\frac{\sin{br}}{r}+ O\left(\frac{1}{r^2}\right).\label{vNW-V2}
\end{equation}
If $|b| <|a|$, the bound state in the continuum (BIC) appears for the energy eigenvalue $E=b^2/4$, that is, the BIC appears for a very specific value of the energy, which is determined by the oscillatory frequency of the potential. The physical interpretation of this phenomenon is that it appears as a result of the destructive interference caused by the multiple crests of the potential.\\
The peculiar behavior of the von Neumann - Wigner potentials meant that, at the time they were proposed, they were considered simply as toy models that could not be present in nature. However, there are recent works that suggest BICs may appear in material systems as dielectric photonic crystals, optical waveguides and fibres, quantum dots,
graphene and topological insulators (see \cite{Nature} and references cited there). The construction of von Neumann-Wigner  potentials, in addition to be considered toy models, have the problem that only one solution to the Schr\" odinger equation is known, which is precisely the bound state in the continuum. Therefore, new mechanisms, based on the supersymmetric quantum mechanics or Darboux transformation, have been created to generate this type of potentials \cite{Pappademos,Mondragon,Nico1,Nico2}. In the next section we will present the mechanism of the degenerated Darboux transformation, which will be used for constructing a von Neumann - Wigner Darboux deformed truncated oscillator.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Degenerated Darboux transformation.}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The Darboux transformation is a mathematical tool widely used for finding solutions to differential equations from a starting one, whose solution is completely known \cite{Nico3,Springer,Nico4}. To establish how it operates, let us consider the radial part of the stationary Schr\" odinger  equation with angular momentum $l=0$:

\begin{equation}
\hat{H}\psi_E(r)=E\psi_E(r),\quad {\rm where}\quad \hat{H}=-\frac{d^2}{dr^2}+V_0(r). \label{DT-Schro}
\end{equation}
With the purpose of constructing the transformation, we define the following first order differential operator
\begin{equation}
\hat{A}=\frac{d}{dr}-\beta(r), \label{DT-A}
\end{equation}
where $\beta$ is, in principle,  a real valued function to be determined. Applying (\ref{DT-A}) to (\ref{DT-Schro}) we get

\begin{equation}
\left[\hat{H}-2\beta'(r)\right]\hat{A}\psi_E(r)+\psi_E(r)\,\frac{d}{dr}\left(V_0-\beta'(r)-\beta^2(r)\right)=E\hat{A}\psi_E(r).\label{DT-Covariance}
\end{equation}
If we choose the beta function in such a way that it satisfies the next Riccati equation

\begin{equation}
-\beta'(r)+V_0(r)-\beta^2(r)=\epsilon,\label{DT-Riccati}
\end{equation}
where $\epsilon$ is a real constant, then equation (\ref{DT-Covariance}) shows the covariance of the Schr\" odinger equation by the action of $\hat{A}$. It only remains to determine the beta function by solving the Riccati equation (\ref{DT-Riccati}). To linearize this equation, the following transformation is proposed:

\begin{equation}
\beta(r)=\frac{d}{dr}\ln{\varphi(r)},\label{DT-beta}
\end{equation}
which maps the Riccati equation into a Schr\" odinger equation type for the initial potential $V_0(r)$ and the function $\varphi(r)$:

\begin{equation}
-\frac{d^2}{dr^2}\varphi(r)+V_0(r)\,\varphi(r)=\epsilon\, \varphi(r).
\end{equation}
Therefore, the function $\varphi(r)$  is nothing more than a solution, not necessarily physical, of the Schr\" odinger equation with eigenvalue $\epsilon$, so we take
\begin{equation}
\varphi(r)\equiv \psi_\epsilon(r).
\end{equation}
In the context of the Darboux transformation (also known in quantum mechanics as factorization method or supersymmetric quantum mechanics) this function is called ``transformation function" and its corresponding eigenvalue ``factorization constant". \\
The latest result can be summarized by saying that the Schr\" odinger equation is covariant under the following transformation:

\begin{eqnarray*}
\psi_E(r) &\rightarrow& \psi_E^{(1)}(r)=\frac{{\rm W}(\psi_\epsilon,\psi_E)}{\psi_\epsilon},\\
V_0(r)&\rightarrow& V_1(r)=V_0(r)-2\frac{d}{dr}\left(\frac{\psi_\epsilon'}{\psi_\epsilon}\right).
\end{eqnarray*}
Here ${\rm W}(\psi_\epsilon,\psi_E)$ stands for the Wronskian of $\psi_\epsilon$ and $\psi_E$. The strength of the Darboux transformation lies in the fact that known  the solutions to the Schr\" odinger equation for the potential $V_0$, one can construct the set of solutions of a new system characterized by the potential $V_1(r)$. However, the transformation function appears in the denominator of the new potential and its corresponding solutions, so if we want to obtain a physical system through the Darboux transformation, we have to take a nodeless transformation function. An alternative to avoid this restriction is to implement a higher order transformation, that is, to take an iteration of Darboux transformations. For the second order case, $\psi_E^{(2)}(r)$ is the eigenfunction of the Schr\" odinger equation for the potential $V_2(r)$ and the eigenvalue $E$, according to the following transformation rule:
\begin{eqnarray}
\psi_E(r) &\rightarrow& \psi_E^{(2)}(r)=\frac{{\rm W}(\psi_{\epsilon_1},\psi_{\epsilon_2},\psi_E)}{{\rm W}(\psi_{\epsilon_1},\psi_{\epsilon_2})},\label{vNW-Psi2}\\[0.3cm]
V_0(r)&\rightarrow& V_2(r)=V_0(r)-2\frac{d^2}{dr^2}\ln{{\rm W}(\psi_{\epsilon_1},\psi_{\epsilon_2})},\label{vNW-V2}
\end{eqnarray}
where $\psi_{\epsilon_1}$ and $\psi_{\epsilon_2}$ are solutions (not necessarily physical solutions) of the initial Schr\" odinger equation, so that we only have to guarantee that the Wronskian of these solutions does not have zeros.\\
We are interested in a special case of the second order Darboux transformation, which is obtained when the two transformation functions are degenerated.  In such a case the function $\psi_{\epsilon_2}$ can be written in terms of $\psi_{\epsilon_1}$ as follows:

\begin{eqnarray*}
\psi_{\epsilon_2}(r)=\psi_{\epsilon_1+\eta}(r),\quad{\rm where}\quad |\eta|\ll |\epsilon_1|,
\end{eqnarray*}
such that the function $\psi_{\epsilon_2}$ can be expanded in Taylor series around $\epsilon_{1}$ into (\ref{vNW-Psi2}) and (\ref{vNW-V2}) and, after taking the limit $\eta\rightarrow0$, we get a degenerated version of the second order Darboux transformation:

\begin{eqnarray}
 \psi_E^{(2)}(r)&=&\frac{{\rm W}(\psi_{\epsilon_1},\partial_{\epsilon_1}\psi_{\epsilon_1},\psi_E)}{{\rm W}(\psi_{\epsilon_1},\partial_{\epsilon_1}\psi_{\epsilon_1})},\label{vNW-dPsi2}\\[0.3cm]
V_2(r)&=&V_0(r)-2\frac{d^2}{dr^2}\ln{{\rm W}(\psi_{\epsilon_1},\partial_{\epsilon_1}\psi_{\epsilon_1})},\label{vNW-dV2}
\end{eqnarray}
where $\partial_{\epsilon_1}\equiv\frac{\partial}{\partial\epsilon_1}$. This type of transformation has the advantage that it can be implemented using as a seed function a scattering state, even when it has an infinity of nodes \cite{Mondragon,Nico1,Nico2,Nico5}.\\
The mechanism presented in this section will be used for constructing a von Neumann - Wigner potential starting from a truncated harmonic oscillator.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Truncated radial harmonic oscillator.}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Let us consider the next stationary Schr\" odinger equation, with zero angular momentum,

\begin{equation}
-\frac{d^2}{dr^2}\psi_E(r)+V_0(r)\, \psi_E=E\psi_E,\label{TRHO-Schro}
\end{equation}
for a radial truncated harmonic oscillator, which is given by the following expression
\begin{eqnarray}
V_0(r)=\left\{
\begin{array}{cc}
r^2-b^2,  & r\leq b  \\
  0,&b<r   \label{TRHO-V}
\end{array}
\right.
\end{eqnarray}
In order that the complete solution will be finite at the origin of coordinates, it must be met that $\psi_E(r=0)=0$. So, the general solution is written as follows

\begin{eqnarray}
\psi_E(r)=\left\{
\begin{array}{cc}
A \,\, _1F_1(a,3/2,r^2)\, r\, e^{-r^2/2}, & r\leq b  \\[0.2cm]
  B e^{ikr}+C e^{-ikr},&b<r   \label{TRHO-Psi0}
\end{array}
\right.
\end{eqnarray}
where $_1F_1$ is the well known confluent hypergeometric function, $a$ is a coefficient which depends on the energy and the cutoff point: $a=(1/4)*(3-k^2-b^2)$; $k^2=E$ and $A$, $B$ and $C$ are constants to be determined. Next we will find the discrete spectrum of the system and its corresponding square integrable wave functions.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Bound  states.}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

We restrict the analysis to the case $E=k^2<0$. In such a case, the kinetic term $k$ is a purely imaginary complex number, so we take $k\rightarrow i\kappa=i\sqrt{|E|}$. Therefore, by demanding the continuity  of the solution at the cut-off point $b$,  together with the square integrable boundary condition, we get the analytical expression for the bound states of the system:
\begin{eqnarray}
\psi_E(r)=A\left\{
\begin{array}{cc}
 \,\, _1F_1(a,3/2;r^2)\, r\, e^{-r^2/2}, & r\leq b  \\[0.2cm]
 _1F_1(a,3/2;b^2)\, b\, e^{(-b^2/2-\kappa b)}  e^{-\kappa r},&b<r   \label{TRHO-PsiBound}
\end{array}
\right.
\end{eqnarray}
where the quantization rule is given by the next trascendental algebraic expression:
\begin{equation}
\frac{(3+\kappa^{2}-b^{2})b^{2}}{3}\, _1F_1\left(a+1,\frac{5}{2};b^{2}\right)-\left(b^{2}-b\kappa-1\right)\, _1F_1 \left(a,\frac{3}{2};b^{2}\right)=0.\label{TRHO-QR}
\end{equation}
The Table \ref{TRHO-Table} shows the discrete spectrum obtained by solving (\ref{TRHO-QR}) for some specific value of the cut-off point, while the Figure \ref{TRHO-Figure} shows the potential and their corresponding three bound states. In the next subsection the scattering regimen will be annalyzed.
\begin{table}
\caption{\label{TRHO-Table} Discrete spectrum of the truncated harmonic oscillator for $b=4$.}
\begin{center}
\begin{tabular}{ll}
\br
Bound states & Energy\\
\mr
Ground state & -12.999\\
\mr
First excited state & -9.000\\
\mr
Second excited state & -5.005\\
\br
\end{tabular}
\end{center}
\end{table}

\begin{figure}
\centering
\subfloat[]{%
\includegraphics[width=0.42\textwidth]{TRHO-Figure.eps}%
\label{fig:a}%
}%
\hfill%
\subfloat[]{%
\includegraphics[width=0.42\textwidth]{Scattering.eps}%
\label{fig:b}%
}%
 \caption{\label{TRHO-Figure} (a) The truncated radial harmonic oscillator (solid line) for $b=4$ and their corresponding bound states (dashed lines). (b) The corresponding scattering state for $k=1$.}
\end{figure}

%\begin{figure}
%\begin{center}
%\includegraphics{TRHO-Figure.eps}
%\end{center}
%\caption{\label{TRHO-Figure} The truncated radial harmonic oscillator (dashed line) for $b=4$ and their corresponding bound states (solid lines).}
%\end{figure}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Scattering states.}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

In this case, let us restrict the energy values to the interval $E>0$ in (\ref{TRHO-Psi0}) and, after taking the continuity conditions at the cut off point, we obtain the expression for the scattering solution:

\begin{eqnarray}
\psi_E(r)=A\left\{
\begin{array}{cc}
 \,\, _1F_1(a,3/2;r^2)\, r\, e^{-r^2/2}, & r\leq b  \\[0.2cm]
D(E,b)\, e^{ikr}+ D^{*}(E,b)\, e^{-ikr},&b<r   \label{TRHO-PsiS}
\end{array}
\right.
\end{eqnarray}
where,
\begin{eqnarray*}
D(k)=\frac{A}{6k}e^{-\frac{1}{2}b(b+2ik)}\left\{ 3[i(b^{2}-1)+bk^{2}]\, _1F_1\left(a,\frac{3}{2};b^{2}\right)+ib^{2}(k^{2}+b^{2}-3)\, _1F_1\left(a+1,\frac{5}{2};b^{2}\right)\right\}
\end{eqnarray*}
The Figure \ref{TRHO-Figure} shows the graphics of a conventional scattering state for a specific value of the energy. As we can see, this kind of solution of the Schr\" odinger equation has an infinity number of zeros and, as we will see, even then it can be used for implementing the degenerated version of the second order Darboux Transformation.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Darboux deformed truncated harmonic oscillator.}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

In this section, we use a special kind of scattering solution (it behaves as a $sin$ function out of the interaction zone) for implementing a degenerated version of the Darboux transformation, which is given by:

\begin{eqnarray}
\psi_E(r)=\left\{
\begin{array}{cc}
 A_i \,\, _1F_1\left(a_{q},\frac{3}{2};r^{2}\right)re^{-\frac{r^{2}}{2}} , & r\leq b  \\[0.2cm]
A_e\,\sin{[qr+\delta]},&b<r   \label{DDT-TF}
\end{array}
\right.
\end{eqnarray}
where  $A_i$ and $A_e$ are the arbitrary constants in the internal and external regions, respectively; while $a_{q}=\frac{3-q^{2}-b^{2}}{4}$ and $q^{2}=E$. The form of the solution imposed in the external zone leads that the continuity and differentiability of the solution are fulfilled only for some specific values of the parameters  $q=\sqrt{E}$,  $b$ and $\delta$ (see Figure \ref{FigureX}). These values are obtained by the next transcendental algebraic expression:

\begin{eqnarray}
b^{2}\frac{(3+q^{2}-b^{2})}{3}\, _1F_1\left(a_{q}+1,\frac{5}{2};b^{2}\right)-[b^{2}+qb\,\cot{(qb+\delta)}-1]\, _1F_1\left(a,\frac{3}{2};b^{2}\right)=0.\label{ContinuityCondition}
\end{eqnarray}

\begin{figure}
\centering
\subfloat[]{%
\includegraphics[width=0.41\textwidth]{Differentiable_transformation_function.eps}%
\label{fig:a}%
}%
\hfill%
\subfloat[]{%
\includegraphics[width=0.41\textwidth]{Not_Differentiable_transformation_function.eps}%
\label{fig:b}%
}%
 \caption{\label{FigureX} (a) Continuous and differentiable scattering state for  the values obtained by solving (\ref{ContinuityCondition}), $b=4$, $\delta =0$ and $q=0.880871$ (b) Non differentiable scattering state at the cut-off point $b=4$,  $\delta =0$ and q=4.}
\end{figure}

However, it is important to mention that the wave functions of the arrival system are not necessarily continuos at the cut-off point, because equation (\ref{vNW-dPsi2}) implies to evaluate second order derivatives of the transformation function. Therefore, to avoid possible discontinuities of the arrival functions, an alternative approach is proposed below.\\

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Darboux deformed potential.}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Since the solution of the initial system is used just as an input for the degenerated Darboux transformation, for the moment we do not should to worry about the continuity of the transformation function, instead we look for the conditions such that the deformed functions are continuous and differentiable. In such a case, we take the next transformation function:

\begin{eqnarray}
\psi_q(r)=\left\{
\begin{array}{cc}
  _1F_1\left(a_{q},\frac{3}{2};r^{2}\right)re^{-\frac{r^{2}}{2}} , & r\leq b  \\[0.2cm]
\sin{[qr+\delta]},&b<r   \label{DDT-TF1}
\end{array}
\right.
\end{eqnarray}
Here we have omitted the coefficients $A_i$ and $A_e$ due the argument exposed above. Substituting (\ref{DDT-TF1}) into (\ref{vNW-dV2}) we obtain the Darboux deformed potential, whose analytical expression is given by

\begin{eqnarray}
V^{(2)}_{q}(r)=\left\{
\begin{array}{cc}
 V_{<}(r), & r\leq b  \\[0.2cm]
32 q^2\frac{\sin{\theta}-q\,\gamma\,\cos{\theta}}{(\sin{2\theta}-2q\gamma)^2}\sin{\theta},&b<r   \label{DDT-V2}
\end{array}
\right.\end{eqnarray}
where $\theta=qr+\delta$, $\gamma=r+\gamma_0$ and $\gamma_0=\partial_q \delta$.

\begin{equation}
V_{<}=r^{2}-b^{2}-4+\frac{4}{r^2}-2\sum_{n=0}^{\infty}\frac{(a_{q})_{n}\Gamma'(a_{q}+n)}{(3/2)_{n}\Gamma(a_{q}+n)n!}\frac{d^{2}}{dr^{2}}\ln\left\{ \ln {\rm W} \left[  _1F_1\left(a_{q},\frac{3}{2},r^{2}\right),r^{2n}\right]\right\}.\label{DDT-V<}
\end{equation}
Here, $(a_q)_n$ and $\Gamma$ are the factorial and Gamma functions, respectively.
\begin{figure}
\centering
\subfloat[]{%
\includegraphics[width=0.41\textwidth]{Potential.eps}%
\label{fig:a}%
}%
\hfill%
\subfloat[]{%
\includegraphics[width=0.41\textwidth]{Potential_discontinuity.eps}%
\label{fig:b}%
}%
\caption{{\label{Figure vNWPot}} (a) Darboux deformed von Neumann Wigner potential for $q=1.65996$ and the next values of the parameters  $b=4$, $\delta=0$ and $\gamma_0=1$. (b) The figure shows a zoom of the discontinuity of the potential at the cut-off point.}
\end{figure}

The Figure (\ref{Figure vNWPot}) shows the plot of  the potential (\ref{DDT-V2}) for some specific parameter values. As we can see, it has an asymptotic divergence at $r=0$, a discontinuity at the cut-off point, an oscillatory behavior and goes to zero as $r$ goes to infinity. Next we explore this last behavior in more detail for $\delta=0$ and $\gamma_0\neq 0$:

\begin{eqnarray*}
\lim_{r\rightarrow\infty} V_q^{(2)}(r)=\lim_{r\rightarrow\infty} 32q^2\frac{[\sin{qr}-q(r+\gamma_0)\cos{qr}]\sin{qr}}{[\sin{2qr}-2q(r+\gamma_0)]^2}\rightarrow -4q\frac{\sin{2qr}}{r}+O\left(\frac{1}{r^2}\right),
\end{eqnarray*}
which is precisely the asymptotic behavior of von Neumann Wigner type potentials, see equation (\ref{vNW-V2}). So, we hope that the potential we have constructed in this section  contains a bound state in the continuum corresponding to the eigenvalue $E=q^2$, which is justly the eigenvalue corresponding to the transformation function.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Darboux deformed wave functions.}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

As we have proceed for calculating the deformed potential, we will use the expressions (\ref{DDT-TF1})  into (\ref{vNW-dPsi2}) to construct the corresponding solutions of the arrival system, without imposing that the transformation function to be continuous and differentiable, because the boundary conditions will be imposed on the arrival general solution given by:

\begin{eqnarray}
\psi_k^{(2)}(r)=\left\{
\begin{array}{cc}
 A\psi_{<}(k,r), & r\leq b,  \\[0.2cm]
B F^{+}(k,r)+C F^{-}(k,r),&b<r ,
\end{array}
\right.\label{DDWF}
\end{eqnarray}
where,
\begin{equation}
\psi_{<}(k,r)=re^{-\frac{r^{2}}{2}}\frac{\sum_{m=0}^{\infty}\frac{(a)_{m}\Gamma'(a_{q}+m)}{(3/2)_{m}\Gamma(a_{q}+m)m!}{\rm W}\left[\, _1F_1\left(a_{q},\frac{3}{2},r^{2}\right),r^{2m},\, _1F_1\left(a,\frac{3}{2},r^{2}\right)\right]}{\sum_{n=0}^{\infty}\frac{(a)_{n}\Gamma'(a_{q}+n)}{(3/2)_{n}\Gamma(a_{q}+n)n!}{\rm W}\left[\, _1F_1\left(a_{q},\frac{3}{2},r^{2}\right),r^{2n}\right]}\label{Psi<}
\end{equation}

\begin{equation}
F^{\pm}(k,r)=\frac{2\gamma q(k^{2}-q^{2})-(k^{2}+q^{2})\mathrm{sin}\,2\theta\pm4ikq\,\mathrm{sin^{2}}\theta}{\mathrm{sin}\,2\theta-2q\gamma}e^{\pm ikr}.\label{PsiPM}
\end{equation}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Deformed bound states.}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Now we look for the conventional bond states of the deformed system $E=k^2<0$, then we take $k=i\kappa=i\sqrt{|E|}$. First of all we have to notice that the solution remains regular at the origin of coordinates because $\psi_\kappa(r=0)=0$, while its asymptotic behavior is determined by the functions $F^{\pm}$, whose limit at infinity is given by

\begin{eqnarray*}
\lim_{r\rightarrow\infty}F^{\pm}(\kappa,r)=-(\kappa^2+q^2)\, e^{\mp \kappa r}.
\end{eqnarray*}

Therefore, to satisfy the square integrable boundary condition we must take $C = 0$ in (\ref{DDWF}). With this in mind and by imposing the continuity of the solution at the cut-off point, we get the bound states of the Darboux deformed system:

\begin{eqnarray}
\psi_{bound}^{(2)}(r)=A\left\{
\begin{array}{cc}
 \psi_{<}^{(2)}(\kappa,r), & r\leq b,  \\[0.2cm]
\frac{ \psi_{<}^{(2)}(\kappa,b)}{F^{+}(\kappa,b)}F^{+}(\kappa,r),&b<r. \label{DD-BoundStates}
\end{array}
\right.
\end{eqnarray}

\begin{figure}
\begin{center}
\includegraphics[scale=0.3]{Bound_states.eps}
\end{center}
\caption{\label{DDT-FigBS} The three non normalized bound states corresponding to the discrete spectrum showed in Table 1 and the potential showed in Figure \ref{Figure vNWPot}. The graphs are shown as if the zero of the wave function were in its corresponding eigenvalue.}
\end{figure}

As we can see in Figure \ref{DDT-FigBS}, the bound states of the Darboux deformed potential (Figure \ref{Figure vNWPot})  corresponding to the discrete spectrum showed in Table 1, fulfill the Sturm theorem, that is, the ground state is nodeless while the first and second excited states have one and two zeros, respectively. For the first two states, the maximum amplitude of probability is in the region of greatest depth of the potential, while the maximum amplitude of probability for the most excited state is in the region near the cut-off point.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Deformed scattering states.}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Now we explore the continuous regime, that is, the case $E=k^2>0$.  Starting once more  from equation (\ref{DDWF}) and imposing the corresponding continuity conditions at  the cut-off point

\begin{equation}
\begin{array}{c}
\left[B F^{+}(k,r)+C F^{-}(k,r)\right]_{r=b}=[A\psi_{<}(k,r)]_{r=b},\\
\left[B \frac{d}{dr}F^{+}(k,r)+C \frac{d}{dr}F^{-}(k,r)\right]_{r=b}=[A \frac{d}{dr}\psi_{<}(k,r)]_{r=b},
\end{array}
\end{equation}
we get the next relationships between the coefficients

\begin{eqnarray*}
B=-A \frac{z_{1}^{*}}{z_{2}-z_{2}^{*}},\quad C=A \frac{z_{1}}{z_{2}-z_{2}^{*}},
\end{eqnarray*}
where
\begin{eqnarray*}
z_{1}=\left[\psi_{<}(k,r)\frac{d}{dr}F^{+}(k,r)-F^{+}(k,r)\frac{d}{dr}\psi_{<}(k,r)\right]_{r=b}
\end{eqnarray*}
and
\begin{eqnarray*}
z_{2}=\left[F^{-}(k,r)\frac{d}{dr}F^{+}(k,r)\right]_{r=b}.
\end{eqnarray*}
Here we have used that $\psi_{<}(k,r)$ is a real valued function and $[F^{+}(k,r)]^{*}=F^{-}(k,r)$. Therefore, the scattering solution of the deformed system, for $k\neq q$, can be written as follows:

\begin{eqnarray}
\psi_{s}^{(2)}(r)=A\left\{
\begin{array}{cc}
 \psi_{<}(k,r), & r\leq b,  \\[0.2cm]
\frac{{\rm Im}\left\{\left[ \psi_{<}(k,r)\frac{d}{dr}F^{+}(k,r)-F^{+}(k,r)\frac{d}{dr} \psi_{<}(k,r)\right]_{r=b}F^{-}(k,r)\right\}}{{\rm Im}\left\{\left[F^{-}(k,r)\frac{d}{dr}F^{+}(k,r)\right]_{r=b}\right\}},&b<r, \label{DD-ScatteringStates}
\end{array}
\right.
\end{eqnarray}
where  ${\rm Im}(z)$ denotes the imaginary part of the complex number $z$. Figure \ref{LastFigure}(a) shows a scattering state of the deformed system for some values of the parameters. Up to this point we have used de degenerated Darboux transformation for constructing the bound and scattering states of the deformed potential showed in Figure (\ref{Figure vNWPot}), which has a von Neumann - Wigner behavior when $r\rightarrow \infty$. Therefore, it is time to examine what happens with the eigenvalue $k=q$ which, according to the asymptotic behavior of the potential, could correspond to a bound state in the continuum.

\begin{figure}
\centering
\subfloat[]{%
\includegraphics[width=0.41\textwidth]{Scattering_DT.eps}%
\label{fig:a}%
}%
\hfill%
\subfloat[]{%
\includegraphics[width=0.41\textwidth]{BIC.eps}%
\label{fig:b}%
}%
\caption{\label{LastFigure} (a) Scattering state of the Darboux deformed system for k=1, b=4, q=1.65996, $\delta=0$, $\gamma_0=1$. (b) The bound state in the continuum for the eigenvalue $k=q=1.65996$.}
\end{figure}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Existence of a bound state in the continuum.}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The Darboux deformed solutions of the arrival systems are written in terms of the Wronskian whose first entry is precisely the transformation function, equation (\ref{vNW-dPsi2}). Therefore, in this scheme, the scattering solution corresponding to $k=q$ is mapped in principle to the trivial solution. However, since we have the liberty to chose the arbitrary constant
$A$ in (\ref{DD-ScatteringStates}), we take $A=\frac{A'}{\psi_{<}(k,b)}$, where $A'$ is a new arbitrary constant. In this case, the limit of the solution for $0<r\leq b$, when $k\rightarrow q$, can be evaluated by the L'Hopital rule, that is,

\begin{equation}
	\lim_{k\rightarrow q}A \psi_{<}(k,r) = A'  \lim_{k\rightarrow q}\frac{\frac{d^2}{dk^2}\psi_{<}(k,r)}{\frac{d^2}{dk^2}\psi_{<}(k,b)}=f(r).
\end{equation}
The explicit form of $f(r)$ is very long and not important at the moment, the only important thing to keep in mind is that $f(r=0)=0$, which guarantees the regularity of the solution at the origin of coordinates. On the other hand, for $r\geq b$, we can to apply again the L'Hopital rule (in this case the rule was applied four times) to obtain the limit of the solution at $k\rightarrow q$,

\begin{eqnarray*}
&&\lim_{k\to q}\frac{{\rm Im}\left\{\left[\psi_{<}(k,r)\partial_{r}F^{+}(k,r)-F^{+}(k,r)\partial_{r}\psi_{<}(k,r)\right]_{r=b}F^{-}(k,r)\right\}}{\psi_{<}(k,b)[{\rm Im}\left[F^{-}(k,r)\partial_{r}F^{+}(k,r))\right]_{r=b}}  = \frac{f_1(q,b,r)}{f_2(q,b)}.
\end{eqnarray*}
The explicit form of the term $f_2(q,b)$ again is not important,  all we have to keep in mind is that it is different from zero. On the other hand, the term $f_1(q,b,r)$ is given by

\begin{eqnarray*}
f_1(q,b,r)&=& \left[\partial^2_k\psi_{<}(k,r)\partial_r {\rm Re}[F^{+} (k,r)]- \partial^3_{k,k,r}\psi_{<} (k,r){\rm Re}[F^{+}(k,r)]\right]_{k=q,r=b} \,g_1(q,r)\\[0.2cm]
&+&2\left[\partial^2_k\psi_{<}(k,r) \partial^2_{k,r}{\rm Im}\left[F^{+}(k,r)\right] - \partial^2_{k,r}\psi_{<}(k,r)\partial_k {\rm Im} \left[F^{+}(k,r)\right]\right]_{k=q,r=b}\, g_2(q,r)\\[0.2cm]
&+&\frac{2}{\gamma_0}\left[\partial^2_k \psi_{<}(k,r) \partial^2_{k,r}{\rm Re}\left[F^{+}(k,r)\right] - \partial^3_{k,k,r}\psi_{<}(k,r) \partial_k {\rm Re}\left[F^{+}(k,r)\right]\right]_{k=q\,,r=b} \,g_3(q,r)\\[0.2cm]
&+&\left[\partial^3_{k,k,r}\psi_{<}(k,r)\partial^2_k {\rm Im}\left[F^{+}(k,r)\right] - \partial^2_k\psi_{<}(k,r)\partial^3_{k,k,r}{\rm Im}\left[F^{+}(k,r)\right]\right]_{k=q\,,r=b}\, g_3(q,r).
\end{eqnarray*}
Here we have used the notation $\partial_{a_1,...,a_n}^n\equiv \frac{\partial^n}{\partial_{a_1}...\partial_{a_n}}$, while the functions $g_i(q,r)$, are given by

\begin{eqnarray*}
g_1(q,r)&=&\frac{(2 \sin{qr} - 2r ) \sin{[2 (q r + \delta)]} -
2 q (q r (3 r + 4 \gamma_0) \cos{qr} +
q r^2 \cos{[2 (q r + \delta)]} + 2 \gamma_0 \sin{qr}}{\sin{2qr}-2q(r+\gamma_0)}\\[0.2cm]
g_2(q,r)&=& 2q \frac{q(r + 2 \gamma_0) \cos{qr} + qr \cos{[2(qr + \delta)]} -
2\cos{\delta} \sin{(q r + \delta)}}{-2q(\gamma_0+r)+\sin{[2(qr+\gamma_0)]}},\\[0.2cm]
g_3(q,r)&=&\frac{2q\sin{(qr + \delta)}}{\sin{[2(qr+\delta)]}-2q(r+\gamma_0)}.
\end{eqnarray*}

Therefore,

\begin{eqnarray*}
\lim_{r\rightarrow\infty}g_1(q,r)\rightarrow qr[\cos{qr} + 3 \cos{(qr + \delta)}],\quad
\lim_{r\rightarrow\infty}g_2(q,r)\rightarrow-q[\cos{qr} + \cos{(qr + \delta)}],\quad
\lim_{r\rightarrow\infty}g_3(q,r)\rightarrow0.
\end{eqnarray*}

From the last expressions we can notice that in order to get a square integrable wave function for $k=q$, the coefficients for $g_1(q,r)$ and $g_2(q,r)$ must be simultaneously zero. Taking into account that

\begin{eqnarray*}\left[{\rm Re}[F^{\pm}(k,r)]\right]_{k=q}=\gamma_0\left[\partial_k{\rm Im}[F^{+}(k,r)]\right]_{k=q}=g_3(q,r),\end{eqnarray*}
this assumption is true for the values of $q$ that fulfills the next algebraic equation

\begin{equation}
\left[-\partial^2_k\psi_{<}(k,r)\partial_{r}g_3(q,r) + \partial^2_{k,r}\psi_{<}(k,r)g_3(q,r)\right]_{k=q,\,\,r=b}=0.
\end{equation}
This last equation is analogous to the quantization rule of conventional bound states. In the sense that the nature of the deformed interaction region, define the energy for which the bound state in the continuum appears. In this case for $b=4$, $\delta=0$ and $\gamma_0=1$, the bound state in the continuum appears for a value of $q=1.65996$. Figure \ref{LastFigure} shows the graphics of this peculiar state. As we can see it goes to zero as $r\rightarrow\infty$. The physical interpretation of these results underlies that a phenomenon of destructive interference is created between the different parts of the dispersed wave and the multiple crests of the potential, with the net effect that the wave amplitude is canceled  for very large values of $r$ and the wave function becomes normalizable.

\section{Concluding remarks.}

Starting from the truncated radial harmonic oscillator and by taking a special scattering solution as transformation function, a degenerated version of the second order Darboux transformation has been used for constructing a von Neumann Wigner potential type. Unlike the method originally proposed by von Neumann and Wigner, in this case we obtain the complete set of solutions: the bound states, the scattering states and a bound state in the continuum that arises from the solution to an algebraic relationship which plays the role of an analogous to the conventional quantization rule. The main ingredients of the method lie in not requiring that the transformation function be continous and differentiable at the cut-off point, but to impose these conditions  in the arrival solutions, as well as the introduction of a seemingly singular term in the definition of the solution for $ k = q $, which at first, by the nature of the transformation, was mapped into the trivial solution.\\[.2cm]

\begin{thebibliography}{9}
\bibitem{vNW} J. von Neumann and E. Wigner 1929 {\it Phys. Z.} {\bf 30}  p 465
\bibitem{Stillinger} F.H. Stillinger and D.R. Herrick 1975 {\it Phys. Rev. A.} {\bf 11} p 446
\bibitem{Anzor} A. Khelashvili and N. Kiknadze 1996 {\it J. Phys. A: Math. Gen.} {\bf 29} 3209
\bibitem{Stahlhofen} A.A. Stahlhofen 1996 {\it J. Phys. A: Math. Gen.} {\bf 29} L581
\bibitem{Nature} C. Hsu, B. Zhen, A. Stone et al. 2016 {\it Nat Rev Mater} {\bf 1} p 16048
\bibitem{Pappademos} J. Pappademos, U. Sukhatme and A. Pagnamenta 1993 {\it Phys. Rev. A.} {\bf 48} p 3525
\bibitem{Mondragon} D. Lohr, E. Hern\' andez, A. Ja\' uregui and A. Mondrag\' on 2018 {\it Rev. Mex. Fis.} {\bf 64}  464
\bibitem{Nico1} N. Fern\' andez-Garc\' ia, E. Hern\' andez, A. J\' auregui and A. Mondrag\' on 2013 {\it J. Phys. A: Math. Theor.} {\bf 46} p 175302
\bibitem{Nico2} N. Fern\' andez-Garc\' ia, E. Hern\' andez, A. J\' auregui and A. Mondrag\' on 2014 {\it J. Phys: Conf. Series} {\bf 512} p 012023
\bibitem{Capasso}F. Capasso et. al 1992 {\it Nature} {\bf 358} 5656
\bibitem{Witten}E. Witten 1981 {\it Nucl. Phys. B} {\bf 188}  513
\bibitem{Mielnik} B. Mielnik 1984 {\it J. Math. Phys.} {\bf 25}  3387
\bibitem{Darboux} V.B. Matveev and M.A. Salle 1991 {\it Darboux Transformations and Solitons} (Berlin Hidelberg: Springer- Verlag)
\bibitem{David} D.J. Fern\' andez C and N Fern\' andez - Garc\' ia 2004 {\it AIP Conference Proceedings} {\bf 744} 236
\bibitem{Oscar} B. Mielnik and O. Rosas-Ortiz 2004 {\it J. Phys. A: Math. Gen.} {\bf 37}  10007
\bibitem{Zurika} Z. Blanco-Garcia, O. Rosas-Ortiz and K. Zelaya 2019 {\it Math. Meth. Appl. Sci.} {\bf 42} 4925
\bibitem{Nico3} N. Fern\' andez-Garc\' ia and O Rosas-Ortiz 2008 {\it Ann. Phys.} {\bf 323}  p 1397
\bibitem{Springer} V.B. Matveev and M.A. Salle 1991 {\it Darboux Transformations and Solitons Berlin: Springer}
\bibitem{Nico4} N. Fern\' andez-Garc\' ia 2007 {\it Rev. Mex. Fis.} {\bf S 53} p 42
\bibitem{Nico5} D. Bermudez, D.J. Fern\' andez C and N. Fern\' andez-Garc\' ia 2012 {\it Phys. Lett. A} {\bf 376} p 692
\end{thebibliography}

\end{document}


\newpage
\section{Static network analysis}

  The bipartite network was created using the users and the words filtered out of stop words and function words. Word list was then additionally limited with Zipf's law in mind: nodes representing $100$ of the most occurring words (not being keywords) and $10\%$ of the words occurring the least were removed from the network (these were with $11$ or less occurrences). Table \ref{tab:filtered_words} shows examples of words that were removed. It is understandable that they would only noise the results.
  \begin{table}[H]
    \begin{subtable}{0.49\textwidth}
      \centering
      \begin{tabularx}{0.75\textwidth}{|L{1}|L{1}|} \hline
        \rowcolor[gray]{0.8} \textbf{The most used} \\\hline
        guys \\
        question \\
        response \\
        lol \\
        btw \\
        \hline
      \end{tabularx}
      \caption{Some of the most used.}
      \label{tab:filtered_words_top}
    \end{subtable}
    \begin{subtable}{0.49\textwidth}
      \centering
      \begin{tabularx}{0.75\textwidth}{|L{1}|L{1}|} \hline
        \rowcolor[gray]{0.8} \textbf{The least used} \\\hline
        wehre \\
        phenominon \\
        inmate \\
        pacino \\
        more \\
        \hline
      \end{tabularx}
      \caption{Some of the least used.}
      \label{tab:filtered_words_bottom}
    \end{subtable}
    \caption{Selected examples of the most and the least used non-keyword words.}
    \label{tab:filtered_words}
  \end{table}

  \subsection{Network simplification}

    Network built using above data was made out of $72,363$ nodes, of which $51,938 (71.77\%$) being users and $20,435 (28.23\%)$ being words, connected by $5,497,840$ edges. This was a massive network in a need of a major simplification. The number of edges was especially important to reduce. I have chosen an edge pruning network simplification, introduced by Zhou \textit{et al.}\cite{ZhouMahlerToivonen2012}. They have proposed a generic framework of network simplification by sharing new methods for pruning the edges while keeping the graph maximally connected. It is important to note that this method is lossy, which means we lose some information from the graph. The method is intended to be used with weighted graphs. In our network, the weights represent the probability that the user have used the word, i.e. the number of times he used this particular word divided by the number of total words he or she wrote. Then, the connectivity would be defined as the maximum probability.

    Additional definitions are required to understand the problem. Let path $P$ be a set of edges $P = {(u_1, u_2), (u_2, u_3), \ldots (u_{k-1}, u_k)} \in E$. I use the notation $P(u_1 \to u_k)$ to represent the path between $u_1$ and $u_k$ ($u_1$ and $u_k$ being endvertices of $P$).

    The problem is parameterised with a \emph{path quality function} $q(P) \to \mathbb{R}^+$. The form of this function is dependent on the type of the graph. In our graph it is the probability that a path exists. We can then assume that the value of any path quality function in this graph is positive, and that a larger value of $q$ indicates better quality.

    Given two nodes $u$ and $v$ in a weighted graph, they might be linked by a direct edge or a path, or none when the graph is disconnected. A simple way of quantifying if and how strongly they are connected is to examine the quality of the best path between them\cite{ToivonenMahlerZhou2010}. Thus, the connectivity between two nodes $u, v \in E$ is defined as
    \begin{equation}
      C(u, v; E) = \left\{
      \begin{array}{l l}
        \mbox{max}_{P \subset E: P(u \to v)} q(P) & \quad \text{if such $P$ exists,}\\
        -\infty & \quad \text{otherwise.}
      \end{array}
      \right.
    \end{equation}
    A natural measure for the \emph{connectivity} of this graph is then the average connectivity over all pairs of nodes
    \begin{equation}
    C(V, E) = \frac{2}{|V|(|V|-1)} \sum_{u, v\in E, u \neq v} C(u, v; E) \mbox{.}
    \end{equation}

    This network was connected so there is no need to calculate the connectivity for each disconnected component and we know that $C(V, E) > 0$.

    The goal would to produce a graph $H(V, F)$ that is simplification of graph $G$ and $F \subset E$ such that the \emph{ratio of connectivity} is maximised. A ratio of connectivity is defined as
    \begin{equation}
     rk (V, E, E_R) = \frac{C(V, E \ E_R)}{C(V, E)} \mbox{,}
    \end{equation}
    where $E_R \subset R$ is a set of edges to be removed from the graph and $C(V, E \ E_R)$ is the connectivity of the graph after edges $E_R$ has been removed. The connectivity of the graph obviously cannot be increased while removing edges, thus $rk = 1$ means that the connectivity was left unchanged, $0 < rk < 1$ means that the removal resulted in some loss of connectivity, while $rk = -\infty$ means that the graph has been disconnected.

    \begin{algorithm}[H]
      \begin{algorithmic}[1]
        \Procedure{PruneNaively}{$G(V, E)$}
          \State Sort edges $E$ by weights in ascending order.
          \State $F \gets E$
          \State $n \gets (|E| - (|V| - 1))$
          \State $i \gets 1$
          \State $j \gets 1$
          \While{$i \leq n$}
            \If{$C(u, v; F \setminus \{e_j\}$ is not $-\infty$}
              \State $F \gets F \setminus {e_j}$
              \State $i \gets i + 1$
            \EndIf
            \State $j \gets j + 1$
          \EndWhile
          \State Return $H = (V, F)$
        \EndProcedure
      \end{algorithmic}
      \caption{Naive approach.}
      \label{alg:pruning_na}
    \end{algorithm}
    I did not have enough time to conduct \emph{optimal} edge pruning so I have decided to conduct pruning randomly using \emph{naive approach} and see its effects, keeping in mind that $rk$ should be between $0$ and $1$. Algorithm \ref{alg:pruning_na} shows the approach I have selected. It sorts edges by their weights in ascending order first and then iteratively removes edges from the top of the lists when this operation would not cause the graph to be cut. The most important reason why I favoured this approach over the \emph{brute force} (that is not described here) algorithm is that it consists of less steps and is much less time consuming (in fact, it is the quickest)\cite{ZhouMahlerToivonen2012}. I could not use \emph{path simplification} or \emph{combinational approach} because it would remove too much information important in my opinion.

    Figure \ref{fig:pruning_effect} shows the effect of the naive approach of pruning. The network has $115$ nodes and $134$ edges. A total of $20$ edges were removed, $19$ of which with a weight of $1$ and $1$ of weight $2$. For that kind of network the results are very good: removal of $\approx 15\%$ edges resulted in only $\approx 4\%$ loss of connectivity. Unfortunately, the average path length has increased from $3.35$ to $5.53$ which is illustrated by the node neighbourhood heat map that was calculated using distance from the node with the greatest degree (the biggest one), with edge weights in mind---the less intense the colour, the more distant the node is.
    \begin{figure}[H]
      \centering
        \begin{subfigure}[b]{0.50\textwidth}
          \includegraphics[width=\textwidth]{chapters/03_implementation/prune_1}
          \caption{Before pruning.}
          \label{fig:prune_1}
        \end{subfigure}
        \qquad
        \begin{subfigure}[b]{0.43\textwidth}
          \includegraphics[width=\textwidth]{chapters/03_implementation/prune_2}
          \caption{After pruning.}
          \label{fig:prune_2}
        \end{subfigure}
      \caption{The effect of pruning of example network.}
      \label{fig:pruning_effect}
    \end{figure}

    The results of pruning of the whole network are very surprising. It was possible to remove $2,613,126$ edges, which makes a $47.53\%$ of the network! The whole process took around 5 minutes and 12 seconds on my setup: one core of Intel i7 (3740QM) processor and 16GB of RAM. What is even more surprising is the fact that the original connectivity was retained. It is very hard to say why it is the case, but with a high probability I would blame the word extraction process, especially the word splitting pattern which after even so many iterations was apparently not perfect enough.

  \subsection{Network properties}
    The network was then evaluated for its basic properties. They are displayed in table \ref{tab:network_props}. $N$, $M$ and $E$ denote the number of users, words and edges connecting them, respectively. $\langle k \rangle$ and $\langle d \rangle$ are the average user degree and average word degree. The network is made up of one connected component. $\gamma_k$ and $\gamma_d$ are the exponents of the power-law degrees of user degree distribution and word degree distribution respectively. $l_G$ is an average path length, $C$ is the global clustering coefficient and $\langle  C_i \rangle$ is the average local clustering coefficient.
    \begin{table}[H]
      \centering
      \begin{tabularx}{\textwidth}{|L{1}|L{1}|L{1.5}|L{1}|L{0.75}|L{1}|L{0.75}|L{1}|L{1}|L{1}|} \hline
        \rowcolor[gray]{0.8} \textbf{N} & \textbf{M} & \textbf{E} & \textbf{$\langle k \rangle$} & $\gamma_k$ & \textbf{$\langle d \rangle$} & $\gamma_d$ & \textbf{$l_G$} & $C$ & $\langle C_i \rangle$ \\\hline
        $51,938$ & $20,435$ & $2,884,714$ & $55.54$ & $1.63$ & $141.23$ & $1.04$ & $2.68$ & $0.0438$ & $0.0121$ \\\hline
      \end{tabularx}
      \caption{Network properties.}
      \label{tab:network_props}
    \end{table}

    Due to the fact that the network is bipartite, we have to check two degree distributions: one for users and one for words they have written. both to follow the power-law
    \begin{equation}
      \begin{split}
        p(k) \sim k^{-\gamma_k} \mbox{,} \\
        p(d) \sim d^{-\gamma_d} \mbox{,}
      \end{split}
    \end{equation}
    with the values of the exponents $\gamma_k$ and $\gamma_d$ shown in table \ref{tab:network_props}.

    Figure \ref{fig:degdist_users} shows degree distribution of user nodes. One of the first things that is noticeable while looking at this figure is that the degree distribution for degrees in a range $[1:30]$ is approximately linear and flat. The reason is that there are a lot of users that sign up to this forum with a particular purpose in mind, such as to ask a question or get a recommendation. They create a single topic for their needs and never discuss outside of it and then never return to the forum after they posted their last message. In fact, users having degree $k \leq 30$ and posting only within a single topic represent $69.35\%$ of all the users having such degree. This \emph{in my opinion} explains why the degree distribution $p(k)$ is skewed as much in the degree range $[1:30]$. If we take the other part of the range, i.e. $[31:3950]$, we see that users like that represent only $17.78\%$ of the users from that degree range.
    What is also interesting is rather large number of \emph{hubs}, i.e. users with degree significantly higher than average. Total number of nodes with degree $k \geq 1000$ is $1.24\%$, which makes one user of 80 an important node.
    \begin{figure}[H]
      \centering
      \includegraphics[width=0.76\textwidth]{chapters/03_implementation/degdist_users}
      \caption{Degree distribution of users.}
      \label{fig:degdist_users}
    \end{figure}

    The degree distribution of word nodes is shown on figure \ref{fig:degdist_words}. There are no surprises here other than the value of the power-law exponent $\gamma_d$ which is very low, especially where we find the value of this exponent in most real-world scale-free networks to be between $2$ and $3$. I think it is quite safe to assume that if we had no typographical errors in the network and we didn't have to conduct the stemming process, the value would be higher.
    \begin{figure}[H]
      \centering
      \includegraphics[width=0.76\textwidth]{chapters/03_implementation/degdist_words}
      \caption{Degree distribution of words.}
      \label{fig:degdist_words}
    \end{figure}


\documentclass[../../main.tex]{subfiles}
\begin{document}
\subsubsection{Associate}
The operation $associate$ establishes a relationship between $k?$ and $v?$ at the top level of $m!$.
\begin{schema}{Associate[KV, K, V]}
  m?, m!, m' : KV \\
  k? : K \\
  v? : V \\
  associate~\_ : KV \cross K \cross V \bij KV\
  \where
  m! = associate(m?, k?, v?) @ \\
  \t1 let ~~ m' == m? ~\ndres ~k? \implies \\
  \t3 (\dom ~m' = \dom ~(~m? \setminus ~k?)) ~\land \\
  \t3 (~m? \setminus ~m' = k? \iff k? \in m?) ~\land \\
  \t3 (~m? \setminus ~m' = \emptyset \iff k? \not \in m? \implies m? = m')\\
  \ \ \ ~ = \ldata k? \mapsto v? \rdata ~\union ~m'
\end{schema}
This implies that any existing mapping at $k? \in m?$ will be overwritten by $associate$
but an existing mapping is not a precondition.
\begin{axdef}
  (k?, m?_{k?}) \in m? ~\lor ~(k?, m?_{k?}) \not \in m? \\
  (k?, m?_{k?}) \not \in m! \\
  (k?, v?) \in m!
  \where
  m! = associate(m?, k?, v?)
\end{axdef}
$associate$ does not alter any other mappings within $m?$ and this property is illustrated by the definition of local variable $m'$
\begin{axdef}
  m' : KV ~ | ~ m' = m? \ndres ~k? \implies m' \dres (m? \setminus ~k?)
  \where
  \dom ~m? = \{~ k_{i} : K ~|~ 0~..~\# ~m? @ k_{i} \in m? ~\land ~~0 ~\leq ~i ~\leq ~\# ~m?\} \\
  \dom ~m' = \{~ k'_{i} : K ~|~ 0~..~\# ~m' @ k'_{i} \in m? ~\land ~k'_{i} \not = k? ~\land ~~0 ~\leq ~i ~\leq ~\# ~m'\} \\
  \dom ~m' = \dom ~m? \iff k? \not \in m? \implies \forall k_{i} \in m? ~|~ k_{i} \not = k? \\
  \# ~m' = \# ~m? \iff k? \not \in m? \\
  \# ~m' = \# ~m? - 1 \iff k? \in m?
\end{axdef}
and its usage within the definition of $associate$.
\begin{zed}
  m! = m? ~\cup ~\ldata ~k? \mapsto v? \rdata \implies k? \not \in m? \\
  m! = m' ~\cup ~\ldata ~k? \mapsto v? \rdata \implies m' \not = m? ~\land ~~k? \in m?
\end{zed}
The following examples demonstrate the intended functionality of $associate$.
\begin{argue}
  M = \ldata k_{0}v_{k_{0}}, k_{1}v_{k_{1}} \rdata \\
  \t1 k_{0} = abc \ \land  v_{k_{0}} = 123 & $k_{0}v_{k_{0}} = abc \mapsto 123$ \\
  \t1 k_{1} = def \ \land v_{k_{1}} = xyz \mapsto 456 & $k_{1}v_{k_{1}} = def \mapsto xyz \mapsto 456$ \\
  associate(M, baz, foo) = \ldata abc \mapsto 123, \ def \mapsto xyz \mapsto 456, \ baz \mapsto foo \rdata \\
  associate(M, abc, 321) = \ldata abc \mapsto 321, \ def \mapsto xyz \mapsto 456 \rdata
\end{argue}
\end{document}


\section{Causal Inference}
Given a \textbf{treatment}, we want to know if there is a \textbf{causality} between the \textbf{treatment and outcome}.

Given a \textbf{control group} and \textbf{treatment group}, if we can observe the before and after treatment for both groups, we can find out different treatment effects:
\begin{itemize}
	\item individual treatment effect: $Y_{1i} - Y_{0i}$
	\item average treatment effect: $E(Y_{1i} - Y_{0i})$
	\item subgroup treatment effect: $E(Y_{1i} - Y_{0i} | X)$
\end{itemize}
However, $Y_{1i}$ and $Y_{0i})$ can't be both observable for one group.

$\rightarrow$ approximation

\subsection{Data Collection in Causal Inference}
\paragraph{Golden Rule} \textbf{randomized controlled trials}. The treatment is controlled, individuals are assigned randomly to the treatment.

$\rightarrow$ Sample selection bias is prevented.

\subsubsection{Different Types of Experiments/Data Collections}
\begin{itemize}
	\item \textbf{Randomized Controlled Trials}: Treatment/Control groups separated. Subject is \textbf{randomly assigned} to the \textbf{treatment/control} group.

	$\rightarrow$ minimum selection bias
	\begin{itemize}
		\item Lab Experiments
		\item Field Experiments
	\end{itemize}

	\item \textbf{Quasi-experiements}: \textbf{natural groups} pre-exist, no separation of control/treatment group beforehand. The independent variable(treatment variable) is \textbf{controlled}, subjects are \textbf{not randomly assigned}.

	$\rightarrow$ selection bias

	\item \textbf{Observational studies}: what we always have. The independent variable is \textbf{not controlled}, individuals \textbf{self-assigned}.

	$\rightarrow$ selection bias
	\begin{itemize}
		\item cross-sectional study
		\item longitudinal study
		\item panel study
		\item case-control study
	\end{itemize}
\end{itemize}

\subsection{Challenges to Quasi-Experiments \& Observational Studies: Confounding Variables \& Identification Strategies}
\subsubsection{Confounding Variables}

 For \textbf{Quasi-Experiments and Observational Studies}, confounding variables might exist, but \textbf{not observable, therefore omitted from the model}. In order to identify precise causal effects, we need to deal with confounding variables.

\paragraph{Confounding Variables} an extraneous variable that is \textbf{unobservable}, which \textbf{correlates} with \textbf{dependent and independent variables}.

$\rightarrow$ $Cov(\varepsilon, X) \neq 0$ $\rightarrow$ Endogeneity

$\rightarrow$ Consequence: biased results.

\subsubsection{Combat Confounding Variables by Data Collection: Randomized Controlled Trials}
Apply Randomized Controlled Trials: confounding variables \textbf{automatically removed}.

Ways to conduct RCTs:
\begin{itemize}
	\item Lab experiment
	\item Field experiement
\end{itemize}
\begin{figure}[H]
	\centering
	\includegraphics[width=0.8\textwidth]{labfield.png}
\end{figure}
\subsubsection{Indentification Strategy for Quasi-Experiments: Difference-in-Difference}
\begin{itemize}
	\item Idea: Observe the \textbf{effect of treatment} controlled by the researcher between \textbf{control \& treatment group}, \textbf{over time}.
	\item Process:
	\begin{itemize}
		\item Assume there exists an \textbf{overall trend} on both control \& treatment group. We still want to estimate the treatment effect while not omitting confounding variable (eg: time).
		\item treatment effect:
		$$\text{Treatment effect} = (Y_{t2} - Y_{t1}) - (Y_{c2} - Y_{c1})$$
	\end{itemize}
\end{itemize}

\subsubsection{Indentification Strategy for Panel Studies: Fixed-Effect Models}
\begin{itemize}
	\item Idea: \textbf{Fixed influence} is omitted as one of the confounding variables in modeling the treatment effect on outcome.

	$\rightarrow$ model \textbf{fixed effect} to soak up \textbf{individual effects on model}.
	\item Fixed-Effect Model: the fixed effect is modeled as an \textbf{additional intercept $\lambda_i$} for \textbf{each individual}.
\end{itemize}

\subsubsection{Indentification Strategy for Observational Studies: Propensity Score Matching}
\begin{itemize}
	\item Idea: in cross-sectional data, find a \textbf{data section} where control \& treatment group has the \textbf{maximum similarity} in covariate distribution.

	$\rightarrow$ resembles \textbf{randomized experiment}

	\item Process:
	\begin{itemize}
		\item estimate \textbf{propensity score} by logistic regression for each individual in \textbf{treatment group}.
		\item \textbf{match} the \textbf{control group} to the treatment group. Find subjects with \textbf{similar propensity score}.
		\item evaluate quality of matching
		\item evaluate \textbf{treatment effect} based on the \textbf{treatment and matched control group}.

	\end{itemize}
\end{itemize}

\subsubsection{Confounding Variable as Instrument Variables}
\paragraph{Instrument} attributes that \textbf{has causal effect} on \textbf{treatment variable}, but \textbf{no causal effect} on \textbf{outcome}.
\begin{itemize}
	\item Modeling Process:
	\begin{itemize}
		\item instruments \textbf{randomly assigned} to the treatment variable
		\item model the relationship between the instrument and treatment variable.
		\item model the relationship between the predicted treatment variable and outcome.
	\end{itemize}
	\item Estimation: 2-stage least square.
\end{itemize}


\subsection{Definite integrals}

Definite integrals are between two points.

\(\int_0^1f(x)dx\)

\subsection{Indefinite integrals}

Indefinite integrals are not. Eg +c at end. The antiderivative.

\(\int f(x)dx\)

\subsection{Unsigned definite integral}

\(\int_{[0,1]}f(x)dx\)