# Notebook Description
This notebook helps find the solution to an initial value problem of a linear ODE of arbitrary order. 

The user must provide:
 * ODE definition
 * Particular solution (for non-homogeneous ODES)
 * A set of solutions to the associated homogeneous ODE
 * Initial conditions

This document will:
 * automate display
 * calculating the Wronskian determinant to determine if the solutions form a fundamental set
 * fit the general solution to the initial conditions

## Environment Setup


```python
from sympy import *
from IPython.display import display, Markdown
from utils import fit_to_initial_conditions, fit_undetermined_coefficients, wronskian_matrix
from utils import constant_coeff_characteristic_roots, roots_to_homogenous_solutions

init_printing(use_latex = True)
```

## Problem Specification


```python
# Define independent variable, by default t
t = symbols('t')

# define solution symbol, by default y. Y symbol is used for
# display and denotation, while y will hold the solution values
y_symbol = symbols('y')
y_func = Function(y_symbol)(t)

# TODO: Define ODE
ode = diff(y_func, t, 3) - 2*diff(y_func, t, 2) + 2*diff(y_func, t) - y_func

# TODO: Define f(t) for non-homoegeneous ODEs, i.e. the e^x in y''+2y'+y=e^x
f = 0

# TODO: define the initial conditions. Like ode coefficients, the index
# indicates the derivative order
t0 = 0
y0 = [0 ,1 ,2]


```

## Problem Summary
A linear ODE defined as 


```python
display(ode)
```

has constant coefficients, so we can find homogenous solutions using the characteristic equation:


```python
root_list = constant_coeff_characteristic_roots(ode, t, y_func)
yh_solutions = roots_to_homogenous_solutions(root_list, t)
```


$r^{3} - 2 r^{2} + 2 r - 1 = 0$



The roots of the characteristic equation are:



$r_{1} = 1$ with multiplicity $1$



$r_{2} = 1 / 2 - \sqrt{3} i / 2$ with multiplicity $1$



$r_{3} = 1 / 2 + \sqrt{3} i / 2$ with multiplicity $1$



Root 1.0 is real with multiplicity 1, resulting in solutions $e^{t}$



Root (0.5-0.8660254037844386j) has multiplicity 1, resulting in solutions 



Root (0.5+0.8660254037844386j) is complex with multiplicity 1, and along with its conjugate results in solutions $e^{t / 2} \cos{\left(\sqrt{3} t / 2 \right)}$, $e^{t / 2} \sin{\left(\sqrt{3} t / 2 \right)}$


These solutions form a fundamental set if their wronskian is not identical to 0:


```python
# Display
w_symbol = symbols("W")
display(Markdown("The wronskian determinant " + latex(w_symbol, mode = "inline") + " is calculated as:"))

w_matrix = wronskian_matrix(t, *yh_solutions)
display(Eq(w_symbol, Determinant(w_matrix), evaluate = False))
w = wronskian(yh_solutions, t)
display(Eq(w_symbol, w, evaluate = False))
```

Since the wronskian is not zero, we have a fundamental set and can write our solution in the form


```python
c_symbols = [symbols("c_%i" % (i+1)) for i in range(len(yh_solutions))]
y = sum([c_symbols[i]*yh_solutions[i] for i in range(len(yh_solutions))])
display(Eq(y_symbol, y, evaluate = False))
```

Since we know our initial conditions, we can determine the values of our constants:


```python
c_values = fit_to_initial_conditions(y, t, c_symbols, t0, y0)
```


Evaluating expression $y = c_{1} e^{t} + c_{2} e^{t / 2} \cos{\left(\sqrt{3} t / 2 \right)} + c_{3} e^{t / 2} \sin{\left(\sqrt{3} t / 2 \right)}$ at $t = 0$ results in the following system of equations:



$y^{(0)}(0)$ = $0 = c_{1} + c_{2}$



$y^{(1)}(0)$ = $1 = c_{1} + c_{2} / 2 + \sqrt{3} c_{3} / 2$



$y^{(2)}(0)$ = $2 = c_{1} - c_{2} / 2 + \sqrt{3} c_{3} / 2$



Solving this linear system of equations gives us $c_{1} = 1$, $c_{2} = -1$, $c_{3} = \sqrt{3} / 3$


We can substitute these values into our equation to find our solution:


```python
y = sum([c_values[i]*yh_solutions[i] for i in range(len(yh_solutions))])
display(Eq(y_symbol, y, evaluate = False))
```


```python

```

69bf049d815f0062604ed761d8878926595c79d3
ipynb
Jupyter Notebook
LinearODE.ipynb
EganJ/MathHomeworkNotebooks
cfc3b2c1b3ccfd9e7b1f73af09ef0be04ab0088b
MIT
LinearODE.ipynb
EganJ/MathHomeworkNotebooks
cfc3b2c1b3ccfd9e7b1f73af09ef0be04ab0088b
MIT
LinearODE.ipynb
EganJ/MathHomeworkNotebooks
cfc3b2c1b3ccfd9e7b1f73af09ef0be04ab0088b
MIT
Qwen/Qwen-72B
1. YES
2. YES