To solve a first order ODE, one constraint is needed (initial value problem, IVP). In the case of a second order ODE, two constraints are needed. **If the constraints are defined at different locations of the domain, then you will be dealing with a Boundary-value problem (BVP)**. Mostly when we use time derivatives we have an IVP and when we have a derivative in space we have to deal with spacial constraints and therefore BVP's. See the following examples:
$$
\frac{dp}{dt} = -p^{3/2} + 5*p_{cst}(1-e^{-t}) \text{ first order ODE -> IVP with 1 constraints } p[0] = 1000
$$
$$
\frac{d^2y}{dt^2} = \frac{dy}{dt} -y + \cos t =0 \text{ second order ODE -> IVP with 2 constraints } y[0] = 2 \text{ and } \left. \frac{dy}{dt} \right|_{t=0} = 5
$$
$$
\frac{d^2T}{dx^2}-\alpha_1(T-T_s) =0 \text{ second order ODE -> BVP with 2 constraints } T[0] = 10 \text{ and }T[-1] = 20
$$
Even for higher ODE orders, the number of constrains required corresponds to the order of the ODE. It is clear that a second order ODE can either be an IVP or a BVP. The former case is common when describing time derivatives and the latter case is common when describing space derivatives. From now on, we focus on BVP.
## Boundary Conditions
A second order ODE BVP of the type:
$$
\frac{d^2y}{dx^2} = g(x,y,\frac{dy}{dx})
$$
with a domain solution $a<=x<=b$ and boundary conditions (or constraints) defined at $a$ and $b$ typically has two types of boundary conditions:
Consider the following equation that describes the deformation $y$ of a beam with length $L$ clamped at $x=0$ and $x=L$:
$$
\frac{d^4y}{dx^4}=\alpha \text{ load}(x)
$$
where $\alpha$ represents the beams material characteristics.
As it is and ODE of fourth order, it needs 4 BCs. The nature of the problem states that the **deformation** and the **slope of the deformation** at the ends is 0, thus, two Dirichlet and two Neumann BCs:
Illustrating the boundary conditions of a fourth order ODE that describes the deformation of a beam
```
## Solving a BVP using Finite Differences
Just like in the initial value problem section, here the derivatives are approximated numerically following a desired method and order of accuracy. Now the domain going from $a$ to $b$ is discretized using a determined number of grid points $n$ and, thus, a number of sub-intervals $N$. There is always one more point than sub-intervals, $n=N+1$. This is the grid (see Figure below) and, if the spacing is regular, then the length of the sub-interval is $\Delta x = (b-a)/N$.
```{figure} figs/grid.svg
:name: grid
Illustration of the grid, highlighting the two external boundary nodes with known temperatures ($T$) and the internal nodes where the temperature values must be estimated.
```
The Boundary Conditions are defined at the end points and the discretization is applied at **almost** every point. This depends on the numerical approximation. The following steps are followed to solve a BVP:
1. Discretization of the differential equation with a numerical approximation of choice
2. Parameter definition
3. Grid creation
4. Define Boundary conditions
5. Building a system of equations according to the discretization: $Ay=b$
6. Solving the system
%% Cell type:markdown id:1f5f7fbe tags:
:::{card}
Lets visualize these steps above with an exercise:
Let's consider the following problem 2nd order differential equation BVP:
$$
\frac{d^2T}{dx^2} - \alpha(T-Ts)= 0, \hspace{5mm} x \in(0,0.1)
$$
$$
T(0)= 473 [K], \hspace{3mm} T(0.1)= 293 [K]
$$
The parameter $\alpha=166$ and your starting temperature $Ts= 293 [K]$
Use the Finite Central Difference method to approximate the above differential equation at 5 equally spaced intervals.