Difference between revisions of "Numerical Methods for Ordinary Differential Equations"

From AstroBaki
Jump to navigationJump to search
Line 78: Line 78:
import numpy as np

Revision as of 00:06, 11 December 2018

Short Topical Videos

Reference Materials

<latex> \documentclass[11pt]{article} \def\inv#1Template:1 \over \def\ddtTemplate:D \over dt \def\mean#1{\left\langle {#1}\right\rangle} \def\sigot{\sigma_{12}} \def\sigto{\sigma_{21}} \def\eval#1{\big|_{#1}} \def\tr{\nabla} \def\dce{\vec\tr\times\vec E} \def\dcb{\vec\tr\times\vec B} \def\wz{\omega_0} \def\ef{\vec E} \def\ato{{A_{21}}} \def\bto{{B_{21}}} \def\bot{{B_{12}}} \def\bfieldTemplate:\vec B \def\apTemplate:A^\prime \def\xp{{x^{\prime}}} \def\yp{{y^{\prime}}} \def\zp{{z^{\prime}}} \def\tp{{t^{\prime}}} \def\upxTemplate:U x^\prime \def\upyTemplate:U y^\prime \def\e#1{\cdot10^{#1}} \def\hf{\frac12} \def\^{\hat } \def\.{\dot } \usepackage{fullpage} \usepackage{amsmath} \usepackage{eufrak}

\begin{document} \section{ Numerical Integration Methods }

Numerical integration is used to solve ODEs that cannot be solved analytically, generally through discretization of the ODE. Since the conception of the modern computer, numerical integration methods have become an essential tool in the physical sciences and beyond. Here we will describe two of many such methods, along with some sample code.

\subsection*{ The Euler Method }

The Euler Method is the simplest numerical integration method, and is most likely the only one you will need to use in C207. It works like this: Imagine you have some ODE:

$$\frac{dy}{dx} = f(x,y)$$

with some initial condition $y(x_0) = y_0$. Now, let's say we want to determine the value of $y_1$ at some new value of $x_1$ that is close to $x_0$. We can estimate this by rearranging the ODE above into the following form:

$$\frac{y_{1} - y_{0}}{x_{1} - x_{0}} = f(x_0,y_0)$$

which we can write as:

$$y_{1} = y_{0} + (x_{1} - x_{0}) f(x_0,y_0) = y_{0} + h f(x_0,y_0)$$

where $(x_{1} - x_{0}) = h$ is called the "step size. We can generalize this equation with the following recursive relation:

$$ y_{i+1} = y_{i} + h f(x_{i},y_{i}) $$

where the step size is typically set as some constant value. As we will see, smaller step sizes produce more accurate integration results. More precisely, the error is on the order of $O(h)$ (i.e., reducing $h$ by a factor of two makes the Euler method twice as accurate).

\\[12pt] \\[12pt]

Now that we have a simple integration scheme, let's walk through a basic example using python. Say our ODE is:

$$\frac{dy}{dx} = y$$

and our initial condition is $y(0) = 1$. We can solve this analytically, but let's see what we get using the Euler method for different values of $h$.

\begin{verbatim} import numpy as np


\subsection*{ The Runge-Kutta Method }

\section{ Monte Carlo Methods }

\subsection*{ Monte Carlo Sampling }

\subsection*{ Markov Chain Monte Carlo }

\end{document} <\latex>