<s>[INST] Discretization of second order ODE, apply Z transform and inverse I have the following ODE:
$\frac{\mathrm{d^2y(t)} }{\mathrm{d} t} + 2\frac{\mathrm{dy(t)} }{\mathrm{d} t}+4y(t)=e^{-2(t-2)}u(t-2)$
With $u(t)$ being the unit step function. I am than asked to discretize the ODE (with sampling T=1), which gave me:
$y(n+2) + 3y(n) = e^{-2(n-2)}u(n-2)$
Next, I'm told to apply the Z transform to the function and later apply the inverse Z transform to find y(n) (initial values y(0) = y(1) = 0):
$z^2Y(z) + 3Y(z) = \frac{1}{z(z-e^{-2})}$
$Y(z) = \frac{1}{z(z-e^{-2})(z^2+3)}$
The problem is, when I apply the inverse Z transform using Wolfram, I get an enormous y(n) which doesn't seem quite right (that is, I don't think the exercise actually expects this result):
$\frac{(e^{2 - 2 n} (i (-i)^n 3^{n/2 + 1/2} e^{2 n} - i i^n 3^{n/2 + 1/2} e^{2 n} + (-i)^n 3^{n/2 + 1} e^{2 n + 2} + i^n 3^{n/2 + 1} e^{2 n + 2} + 18 e^6) (1 - θ(1 - n)))}{(18 (1 + 3 e^4))}$
I imagine that I can simplify the result using some clever Z transform properties, but I couldn't get very far with that thought. Is there something I'm doing wrong? Is there, maybe, a nice property of the transform that I could apply here? I've been stuck in this exercise for the last few days now.
 [/INST] You can perform partial fractions and simplify first.
Let,
$${Y(z)} = \frac{1}{z(z-e^{-2})(z+\sqrt3i)(z-\sqrt3i)} =\frac{a}{z}+\frac{b}{z-e^{-2}}+\frac{c}{z+\sqrt3i}+\frac{c^*}{z-\sqrt3i}$$
$z = 0 \Rightarrow a = -\dfrac{e^2}{3}$
$z= e^{-2} \Rightarrow b = \dfrac{e^6}{1+3e^4}$
$z = -\sqrt3i \Rightarrow c =\dfrac{1}{-\sqrt3i(-\sqrt3i-e^{-2})(-2\sqrt3i)}= \dfrac{1}{6(\sqrt3i+e^{-2})} = \dfrac{e^{-2}-\sqrt3i}{6(3+e^{-4})} =\dfrac{e^2(1-e^2\sqrt3i)}{6(1+3e^4)}$
and $c^* = \dfrac{e^2(1+e^2\sqrt3i)}{6(1+3e^4)}$
So,
$\begin{align}\dfrac{c}{z+\sqrt3i}+\dfrac{c^*}{z-\sqrt3i} &= \dfrac{1}{6\sqrt3(1+e^{-4})(z^2+3)}\left[(z-\sqrt3i)(1+e^{-2}i)+(z+\sqrt3i)(1-e^{-2}i)\right]\\&=\dfrac{z+\sqrt3e^{-2}}{3\sqrt3(1+e^{-4})(z^2+3)}=\dfrac{1}{3\sqrt3(1+e^{-4})}\left[\frac{z}{z^2+3}\right]\end{align}$

The answer will depend on the Region of Convergence. Let us assume $|z| > \sqrt3 > e^{-2}$
$\begin{align}Y(z) &= \frac{a}{z}+\frac{b}{z-e^{-2}}+\frac{c}{z+\sqrt3i}+\frac{c^*}{z-\sqrt3i} \\&= \frac az + z^{-1}\left[b\frac{z}{z-e^{-2}}+c\frac{z}{z+\sqrt3i}+c^*\frac{z}{z-\sqrt3i}\right] \\
y(n) &= a\delta(n) +(be^{-2(n-1)}+c(-\sqrt3i)^{n-1}+c^*(\sqrt3i)^{n-1})u(n-1) \\
y(n)&=-\frac{e^2}{3}\delta(n)+\left[\frac{e^{8-2n}}{1+3e^4} + c(-\sqrt 3 i)^{n-1} + c^*(\sqrt 3 i)^{n-1}\right]u(n-1)\end{align} $


$$c(-\sqrt 3 i)^{n-1} + c^*(\sqrt 3 i)^{n-1} = \dfrac{e^23^{\frac n2-\frac12}\left[e^23^\frac 12 \left(i^{n} + (-i)^{n}\right) + i^{n-1}+(-i)^{n-1}\right]}{6(1+3e^4)}$$

So,
$$y(n) = -\frac{e^2}{3}\delta(n)+\dfrac{6e^{8-2n}+e^23^{\frac n2-\frac12}\left[e^23^\frac 12 \left(i^{n} + (-i)^{n}\right) + i^{n-1}+(-i)^{n-1}\right]}{6(1+3e^4)}u(n-1)$$
This can be further simplified using $\frac{i^n+(-i)^n}{2} = \frac{e^{i n \frac\pi2} + e^{-i n \frac\pi2}}{2} = \cos\left(\frac{n\pi}{2}\right)$
Finally (for the assumed ROC),

$$y(n) = -\frac{e^2}{3}\delta(n)+\dfrac{3e^{8-2n}+e^23^{\frac n2-\frac12}\left[e^23^\frac 12 \cos\left(\frac{n\pi}{2}\right) + \cos\left(\frac{(n-1)\pi}{2}\right)\right]}{3(1+3e^4)}u(n-1)$$

Similarly you can find for different ROC's
</s>