Z Transform Difference
1. **Problem statement:** Solve the difference equation $$y_{n+2} - 7y_{n+1} + 12y_n = 2^n$$ with initial conditions $$y_0 = 0$$ and $$y_1 = 0$$ using the Z-transform.
2. **Recall the Z-transform definition:** For a sequence $$y_n$$, the Z-transform is $$Y(z) = \sum_{n=0}^\infty y_n z^{-n}$$.
3. **Apply the Z-transform to each term:**
- $$Z\{y_{n+2}\} = z^2 Y(z) - z^2 y_0 - z y_1$$
- $$Z\{y_{n+1}\} = z Y(z) - z y_0$$
- $$Z\{y_n\} = Y(z)$$
4. **Apply the Z-transform to the right side:**
- $$Z\{2^n\} = \frac{z}{z-2}$$ for $$|z| > 2$$.
5. **Substitute into the equation:**
$$z^2 Y(z) - z^2 y_0 - z y_1 - 7(z Y(z) - z y_0) + 12 Y(z) = \frac{z}{z-2}$$
6. **Plug in initial conditions $$y_0=0$$ and $$y_1=0$$:**
$$z^2 Y(z) - 0 - 0 - 7(z Y(z) - 0) + 12 Y(z) = \frac{z}{z-2}$$
7. **Simplify:**
$$z^2 Y(z) - 7 z Y(z) + 12 Y(z) = \frac{z}{z-2}$$
8. **Factor out $$Y(z)$$:**
$$Y(z)(z^2 - 7 z + 12) = \frac{z}{z-2}$$
9. **Factor the quadratic:**
$$z^2 - 7 z + 12 = (z-3)(z-4)$$
10. **Solve for $$Y(z)$$:**
$$Y(z) = \frac{z}{(z-2)(z-3)(z-4)}$$
11. **Partial fraction decomposition:**
Assume
$$\frac{z}{(z-2)(z-3)(z-4)} = \frac{A}{z-2} + \frac{B}{z-3} + \frac{C}{z-4}$$
Multiply both sides by denominator:
$$z = A(z-3)(z-4) + B(z-2)(z-4) + C(z-2)(z-3)$$
12. **Find coefficients by plugging values:**
- For $$z=2$$:
$$2 = A(2-3)(2-4) = A(-1)(-2) = 2A \Rightarrow A=1$$
- For $$z=3$$:
$$3 = B(3-2)(3-4) = B(1)(-1) = -B \Rightarrow B = -3$$
- For $$z=4$$:
$$4 = C(4-2)(4-3) = C(2)(1) = 2C \Rightarrow C=2$$
13. **Rewrite $$Y(z)$$:**
$$Y(z) = \frac{1}{z-2} - \frac{3}{z-3} + \frac{2}{z-4}$$
14. **Inverse Z-transform:**
Recall $$Z^{-1}\left\{ \frac{1}{z-a} \right\} = a^n u_n$$ where $$u_n$$ is the unit step.
So,
$$y_n = 1 \cdot 2^n - 3 \cdot 3^n + 2 \cdot 4^n$$
15. **Check initial conditions:**
- $$y_0 = 1 - 3 + 2 = 0$$
- $$y_1 = 2 - 9 + 8 = 1$$ but initial condition is 0, so we must consider the initial conditions carefully.
16. **Adjust for initial conditions:**
The solution above is the particular solution. The homogeneous solution is:
$$y_n^h = K_1 3^n + K_2 4^n$$
General solution:
$$y_n = y_n^p + y_n^h = A 2^n + B 3^n + C 4^n$$
From the partial fractions, particular solution is:
$$y_n^p = 2^n$$
So,
$$y_n = 2^n + K_1 3^n + K_2 4^n$$
17. **Apply initial conditions:**
- $$y_0 = 2^0 + K_1 3^0 + K_2 4^0 = 1 + K_1 + K_2 = 0$$
- $$y_1 = 2^1 + K_1 3^1 + K_2 4^1 = 2 + 3 K_1 + 4 K_2 = 0$$
18. **Solve system:**
From first:
$$K_1 + K_2 = -1$$
From second:
$$3 K_1 + 4 K_2 = -2$$
Multiply first by 3:
$$3 K_1 + 3 K_2 = -3$$
Subtract from second:
$$(3 K_1 + 4 K_2) - (3 K_1 + 3 K_2) = -2 - (-3) \Rightarrow K_2 = 1$$
Then,
$$K_1 = -1 - K_2 = -1 - 1 = -2$$
19. **Final solution:**
$$y_n = 2^n - 2 \cdot 3^n + 1 \cdot 4^n = 2^n - 2 \cdot 3^n + 4^n$$