```python
import loader
from sympy import *
init_printing()
from root.solver import *
```

#### Solve $y'' - 4y' + 4y = 2t^2 e^{2t}$ using the method of undetermined coefficients


```python
coeffs = [1, -4, 4]
yc, p = nth_order_const_coeff(*coeffs)
p.display()
yp, p = undetermined_coefficients(yc, coeffs, 2 * t ** 2 * exp(2*t))
p.display()
```


$\displaystyle \text{Characteristic equation: }$



$\displaystyle r^{2} - 4 r + 4 = 0$



$\displaystyle \text{Roots: }\left\{ \begin{array}{ll}r_{1,2} = 2\\\end{array} \right.$



$\displaystyle \text{General Solution: }$



$\displaystyle y = \left(C_{1} + C_{2} t\right) e^{2 t}$



$\displaystyle \text{Find }Y(t)\text{ that mimics the form of }g(t)$



$\displaystyle Y{\left (t \right )} = A_{0} t^{2} e^{2 t} + A_{1} t^{4} e^{2 t} + A_{2} t^{3} e^{2 t}$



$\displaystyle \text{Compute successive derivatives of }Y(t)$



$\displaystyle \begin{align*}&Y{\left (t \right )} = t^{2} \left(A_{0} + A_{1} t^{2} + A_{2} t\right) e^{2 t}\\&\frac{d}{d t} Y{\left (t \right )} = t \left(2 A_{0} t + 2 A_{0} + 2 A_{1} t^{3} + 4 A_{1} t^{2} + 2 A_{2} t^{2} + 3 A_{2} t\right) e^{2 t}\\&\frac{d^{2}}{d t^{2}} Y{\left (t \right )} = 2 \left(2 A_{0} t^{2} + 4 A_{0} t + A_{0} + 2 A_{1} t^{4} + 8 A_{1} t^{3} + 6 A_{1} t^{2} + 2 A_{2} t^{3} + 6 A_{2} t^{2} + 3 A_{2} t\right) e^{2 t}\\\end{align*}$



$\displaystyle \text{Plug the derivatives into the LHS and equate coefficients}$



$\displaystyle \begin{align*}&4 t^{2} \left(A_{0} + A_{1} t^{2} + A_{2} t\right) e^{2 t} - 4 t \left(2 A_{0} t + 2 A_{0} + 2 A_{1} t^{3} + 4 A_{1} t^{2} + 2 A_{2} t^{2} + 3 A_{2} t\right) e^{2 t} + 2 \left(2 A_{0} t^{2} + 4 A_{0} t + A_{0} + 2 A_{1} t^{4} + 8 A_{1} t^{3} + 6 A_{1} t^{2} + 2 A_{2} t^{3} + 6 A_{2} t^{2} + 3 A_{2} t\right) e^{2 t} = 2 t^{2} e^{2 t}\\&2 A_{0} e^{2 t} + 12 A_{1} t^{2} e^{2 t} + 6 A_{2} t e^{2 t} = 2 t^{2} e^{2 t}\\\end{align*}$



$\displaystyle \left\{ \begin{array}{ll}12 A_{1} - 2 = 0\\0 = 0\\0 = 0\\6 A_{2} = 0\\2 A_{0} = 0\\\end{array} \right.$



$\displaystyle \text{Solve for the undetermined coefficients}$



$\displaystyle \left\{ \begin{array}{ll}A_{0} = 0\\A_{1} = \frac{1}{6}\\A_{2} = 0\\\end{array} \right.$



$\displaystyle \text{Substitute the coefficients to get the particular solution}$



$\displaystyle y_{p} = \frac{t^{4} e^{2 t}}{6}$


#### Given that ${1, \cos(t), \sin(t)}$ are the complementary solutions of $y''' + y' = 2\cos(2t) + 3\sin(t)$, find the particular solution. 


```python
yp, p = undetermined_coefficients([1, cos(t), sin(t)], [1, 0, 1, 0], 2*cos(2*t) + 3*sin(t))
p.display()
```


$\displaystyle \text{Find }Y(t)\text{ that mimics the form of }g(t)$



$\displaystyle Y{\left (t \right )} = A_{0} t \cos{\left (t \right )} + A_{1} \cos{\left (2 t \right )} + A_{2} t \sin{\left (t \right )} + A_{3} \sin{\left (2 t \right )}$



$\displaystyle \text{Compute successive derivatives of }Y(t)$



$\displaystyle \begin{align*}&Y{\left (t \right )} = A_{0} t \cos{\left (t \right )} + A_{1} \cos{\left (2 t \right )} + A_{2} t \sin{\left (t \right )} + A_{3} \sin{\left (2 t \right )}\\&\frac{d}{d t} Y{\left (t \right )} = - A_{0} t \sin{\left (t \right )} + A_{0} \cos{\left (t \right )} - 2 A_{1} \sin{\left (2 t \right )} + A_{2} t \cos{\left (t \right )} + A_{2} \sin{\left (t \right )} + 2 A_{3} \cos{\left (2 t \right )}\\&\frac{d^{2}}{d t^{2}} Y{\left (t \right )} = - A_{0} t \cos{\left (t \right )} - 2 A_{0} \sin{\left (t \right )} - 4 A_{1} \cos{\left (2 t \right )} - A_{2} t \sin{\left (t \right )} + 2 A_{2} \cos{\left (t \right )} - 4 A_{3} \sin{\left (2 t \right )}\\&\frac{d^{3}}{d t^{3}} Y{\left (t \right )} = A_{0} t \sin{\left (t \right )} - 3 A_{0} \cos{\left (t \right )} + 8 A_{1} \sin{\left (2 t \right )} - A_{2} t \cos{\left (t \right )} - 3 A_{2} \sin{\left (t \right )} - 8 A_{3} \cos{\left (2 t \right )}\\\end{align*}$



$\displaystyle \text{Plug the derivatives into the LHS and equate coefficients}$



$\displaystyle \begin{align*}&- 2 A_{0} \cos{\left (t \right )} + 6 A_{1} \sin{\left (2 t \right )} - 2 A_{2} \sin{\left (t \right )} - 6 A_{3} \cos{\left (2 t \right )} = 3 \sin{\left (t \right )} + 2 \cos{\left (2 t \right )}\\&- 2 A_{0} \cos{\left (t \right )} + 6 A_{1} \sin{\left (2 t \right )} - 2 A_{2} \sin{\left (t \right )} - 6 A_{3} \cos{\left (2 t \right )} = 3 \sin{\left (t \right )} + 2 \cos{\left (2 t \right )}\\\end{align*}$



$\displaystyle \left\{ \begin{array}{ll}0 = 0\\- 2 A_{2} - 3 = 0\\0 = 0\\6 A_{1} = 0\\- 6 A_{3} - 2 = 0\\- 2 A_{0} = 0\\\end{array} \right.$



$\displaystyle \text{Solve for the undetermined coefficients}$



$\displaystyle \left\{ \begin{array}{ll}A_{0} = 0\\A_{1} = 0\\A_{2} = - \frac{3}{2}\\A_{3} = - \frac{1}{3}\\\end{array} \right.$



$\displaystyle \text{Substitute the coefficients to get the particular solution}$



$\displaystyle y_{p} = - \frac{3 t}{2} \sin{\left (t \right )} - \frac{\sin{\left (2 t \right )}}{3}$



```python

```

6226536cc76e3610eccb479be3f4938623249562
ipynb
Jupyter Notebook
notebooks/undetermined-coefficients.ipynb
kaiyingshan/ode-solver
30c6798efe9c35a088b2c6043493470701641042
MIT
2019-02-17T23:15:20.000Z
2019-02-17T23:15:27.000Z
notebooks/undetermined-coefficients.ipynb
kaiyingshan/ode-solver
30c6798efe9c35a088b2c6043493470701641042
MIT
notebooks/undetermined-coefficients.ipynb
kaiyingshan/ode-solver
30c6798efe9c35a088b2c6043493470701641042
MIT
Qwen/Qwen-72B
1. YES
2. YES