Download presentation
Presentation is loading. Please wait.
1
Ordinary differential equaltions:
Solutions by finite difference schemes
2
Ordinary differential equations
1st order ode Taylor expansion of x(t) about time t we thus have an approximation for x(t+dt) in terms of x(t) this is the (explicit) Euler discretization scheme
3
we can get a better approximation if we take two steps
to get from t to t+dt first get an approximation for x(t+dt/2) using the Euler discretization then make the full step using the function evaluated at this midpoint this is the 2nd order Runge-Kutta discretization
4
Example: Analytic solution: Euler method: So this misses the term as expected Runge-Kutta method: So this misses the term, as expected
5
#include <stdio.h>
#include <stdlib.h> #include <math.h> /* set up the finite-difference parameters */ const int runLength=1000; const double delta_t=0.01; /* set up the function prototypes */ double Euler(double x,double t); double RungeKutta(double x,double t); double function(double x,double t); void printData(double *xEuler,double *xRungeKutta); main() { /* define the arrays to store the data */ double xEuler[runLength]={0.0},xRungeKutta[runLength]={0.0},t=0.0; /* set the initial conditions */ xEuler[0]=1.0; xRungeKutta[0]=1.0; /* evolve the solutions using the two integration methods */ for(int n=0;n<runLength-1;++n){ xEuler[n+1]=Euler(xEuler[n],t); xRungeKutta[n+1]=RungeKutta(xRungeKutta[n],t); t=t+delta_t; } printData(xEuler,xRungeKutta);
9
general 2nd order ode: write as two first order equations solve using 2nd order Runge-Kutta half step full step
10
Example: Simple harmonic oscillator Initial conditions: Analytic solution: i.e. Runge-Kutta method:
11
Choosing an algorithm:
accuracy how accurate is the algorithm? how accurate does the answer need to be? efficiency can I use a different, more efficient algorithm? can I implement the current algorithm more efficiently? stability is the algorithm stable? Can I avoid instabilities?
12
Numerical stability: numerical methods approximate continuous differential equations by discrete difference equations the difference equations may exhibit instabilities even if the continuous differential equations don’t two possible reasons are: time-step problems competing solutions
13
Time-step problems: e.g.
has the analytic solution which is a decaying exponential The Euler approximation has Which we can analyze by changing dt good solution vanishing solution decaying oscillations constant amplitude oscillations--- increasing amplitude oscillations-
14
=1.0)
15
Competing solutions: e.g. with boundary conditions:
has the analytic solution which is a decaying exponential: However, the general solution is there are small errors in any finite difference scheme these errors have the effect of introducing some of the growing mode solution. This leads to a numerical solution which grows, rather than decays.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.