Solution (source code)

= Solution

Let $z_r$ be either endpoint at which $Z_r$ is prescribed, and put $d_z=z-z_r$, $q=\mu p_\beta$ and $\kappa=\omega p_\beta$. Integrating the constant-coefficient <velocity>–<traction> system gives
$$
\begin{pmatrix}V(z)\\T(z)\end{pmatrix}
=\begin{pmatrix}\cos\kappa d_z&-i\sin(\kappa d_z)/q\\-iq\sin\kappa d_z&\cos\kappa d_z\end{pmatrix}
\begin{pmatrix}V_r\\-Z_rV_r\end{pmatrix}.
$$
Taking the ratio $-T/V$ yields the <uniform-layer SH impedance update> and its accompanying <velocity>:
$$
\boxed{Z(z)=\frac{Z_r\cos\kappa d_z+iq\sin\kappa d_z}{\cos\kappa d_z+i(Z_r/q)\sin\kappa d_z},\qquad
V(z)=V_r\left[\cos\kappa d_z+i\frac{Z_r}{q}\sin\kappa d_z\right].}
$$
The initial value $V_r$ sets an arbitrary normalization; specifying impedance alone cannot specify the overall wave <wave amplitude>. Positive $d_z$ propagates data from $z_0$, while negative $d_z$ propagates a specified load from $z_1$, so the same expressions solve both requested initial-value problems.

Expanding sine and cosine gives
$$
\boxed{V(z)=\frac{V_r}{2}\left(1+\frac{Z_r}q\right)e^{i\kappa(z-z_r)}
+\frac{V_r}{2}\left(1-\frac{Z_r}q\right)e^{-i\kappa(z-z_r)}.}
$$
Absorbing the reference-point phases into the two constants gives the requested forward/backward exponential superposition. Equivalently, wherever the ratios are defined,
$$
\frac{Z(z)-q}{Z(z)+q}=\frac{Z_r-q}{Z_r+q}e^{-2i\kappa(z-z_r)}.
$$
The exceptional values $Z_r=q,-q$ give the pure directional solutions. If a denominator in the impedance formula vanishes, propagate the finite pair $(V,T)$ through that point; this is an impedance-chart pole, not a failure of the physical solution. The upper-half-plane assumptions ensure $q\ne0$.