# ODEnotes

certik edited this page Feb 8, 2011 · 1 revision

# ODE and FEM notes

We show three different problems (case 1, 2 and 3 below) that can be solved analytically and then how to solve them using Runge Kutta and finite element method. This shows that some things are easy in FEM and difficult using Runge-Kutta.

## Typical ODE problem

Let's say I want to solve this equation on the interval $(0, \pi)$:

$\frac{d^2}{d x^2} f(x) + f(x) = 0$

# Analytic

This has the general solution

$f(x) = A sin(x) + B cos(x)$
where A and B is arbitrary. You need to prescribe some conditions to determine A and B. Some options:

### case 1

$f(0) = 0$
$f'(0) = 1$
This determines $A=1$ and $B=0$.

### case 2

$f(0) = f(\pi) = 0$
This determines $B=0$, but $A$ can still be arbitrary.

### case 3

$f(0) = 0$
$f'(\pi) = -1$
This determines $A=1$ and $B=0$.

# Runge-Kutta

## case 1

This initial (boundary) condition is used in the runge-kutta integrator and one then integrates the whole equation on the interval $(0, \pi)$, the result will be $f(x)=sin(x)$.

## case 2

I don't know any way how to solve such a problem using runge-kutta. I would just try all possible values for $f'(0)$ and iteratively try to satisfy the second condition at the other end of the interval.

## case 3

I don't know any way how to solve such a problem using runge-kutta. I would just try all possible values for $f'(0)$ and iteratively try to satisfy the second condition at the other end of the interval.

# FEM

## case 1

One substitutes

$f(x)=g(x)+x$
and gets
$g(x)+g(x)=-x$
with boundary conditions $g(x)=0$ and $g'(x)=0$, that can be solved using FEM with appropriate test functions.

## case 2

One needs to first rewrite the equation to the weak formulation

$\int_0^\pi -f'(x)v'(x)dx + \int_0^\pi f(x)v(x) dx = - [f'(x)]^\pi_0$
we can even rewrite the right hand side if we want:
$\int_0^\pi -f'(x)v'(x)dx + \int_0^\pi f(x)v(x) dx = - f'(\pi) v(\pi) + f'(0)v(0)$
In order to satisfy $f(0)=f(\pi)=0$ we choose such test functions that satisfy this condition, so the right hand side is 0:
$\int_0^\pi -f'(x)v'(x)dx + \int_0^\pi f(x)v(x) dx = 0$
and now we choose some basis, assemble the global system of equations:
$Ax=0$
and solve it. In this particular case, we get a zero solution numerically, but in principle $A sin(x)$ should be a solution of such a system too.

## case 3

Weak formulation:

$\int_0^\pi -f'(x)v'(x)dx + \int_0^\pi f(x)v(x) dx = v(\pi) + f'(0)v(0)$
Again we choose such test functions, to satisfy v(0) = 0, so we endup with:
$\int_0^\pi -f'(x)v'(x)dx + \int_0^\pi f(x)v(x) dx = v(\pi)$
we assemble the global system
$Ax=b$
where now we have nonzero right hand side and we should get $sin(x)$ as the only solution.