1.Numerical differentiation and quadrature Discrete differentiation and integration Ordinary differential equations Euler’s method, Runge-Kutta methods Systems of differential equations Initial value and boundary value problem Shooting method Numeriska beräkningar i Naturvetenskap och Teknik
f in the points: x 0 ±h Taylor expansion around x 0 =0 gives Maclaurin: Derivative Numeriska beräkningar i Naturvetenskap och Teknik
Derivative with Taylor expansion Difference Derivative in point form Local error Numeriska beräkningar i Naturvetenskap och Teknik
“Forward difference” Compare to the definition of the derivative : Local error In the same way: Numeriska beräkningar i Naturvetenskap och Teknik
Ordinary differential equations An ordinary differential equation is defined as: First order Second order Numeriska beräkningar i Naturvetenskap och Teknik
Euler’s method, discrete solution of first order ordinary diff. equations Based on the “forward difference” given above: which gives: Numeriska beräkningar i Naturvetenskap och Teknik
Runge-Kutta methods Start by integrating between step n and n+1 Taylor approx of f around the central point n+1/2 Integrate: Numeriska beräkningar i Naturvetenskap och Teknik
i.e. Numeriska beräkningar i Naturvetenskap och Teknik
Now one needs an estimate of f n+1/2 in the expression: Use Euler! At half way between points: i.e. with: Runge-Kutta of order 2 is given by: Numeriska beräkningar i Naturvetenskap och Teknik
Runge-Kutta of order 2 y n+1 to order h 3 at the cost of calculating f(x,y) in two points. Geometrical picture: x y Numeriska beräkningar i Naturvetenskap och Teknik
Runge-Kutta error of order 4 > rk3 Numeriska beräkningar i Naturvetenskap och Teknik
Runge-Kutta error of order 5 > rk4 Numeriska beräkningar i Naturvetenskap och Teknik
Exemple; solve with Euler’s method and RK4 and study precision Note that the solution is: …possibly another function Numeriska beräkningar i Naturvetenskap och Teknik
Higher order ordinary differential equations Can be solved as a system of first order equations by substitution: So, an ordinary differential equation of order n can be solved numerically by e.g. RK4 as defined for a first order ordinary differential equation. Numeriska beräkningar i Naturvetenskap och Teknik
condition on y’ Conditions A differential equation of order n is completely determined only if n conditions are are given for the solution. Compare to the simple differential equation: Initial value problems condition on y Conditions given for the same value of the independent variable. An example for the case above is: y’(0)=2, y(0)=0. In classical mechanics this could e.g. correspond to knowing the position and velocity at a given time. Numeriska beräkningar i Naturvetenskap och Teknik
On the board… Numeriska beräkningar i Naturvetenskap och Teknik Second example on the board… Second order equation transferred to system.
Boundary value problems In this case one knows the value of the function (and/or its derivatives) for different values of the independent variable. An exemple from physics is the case of a second order differential equation : There are several ways of solving this problem numerically. A simple method is to transfer the problem to become an initial value problem: and find values for γ that gives solutions that ”shoot over” or ”under” the boundary value in point b. The value forγ which gives a value for y(b) within a given accuracy from βis then solved for. This method is called the “shooting method”. See page 329… Numeriska beräkningar i Naturvetenskap och Teknik
Boundary value problem Numeriska beräkningar i Naturvetenskap och Teknik
Boundary value problem dvs Numeriska beräkningar i Naturvetenskap och Teknik
Boundary value problem Numeriska beräkningar i Naturvetenskap och Teknik
Example, boundary value problem Numeriska beräkningar i Naturvetenskap och Teknik
Quadrature: Trapetzoidal rule Linear interpolation Numeriska beräkningar i Naturvetenskap och Teknik
Trapetzoidal rule Area between x-h and x+h hh f -1 f1f1 f0f0 Numeriska beräkningar i Naturvetenskap och Teknik
Trapetzoidal rule with error estimate: f -1 f0f0 f1f1 h h Numeriska beräkningar i Naturvetenskap och Teknik
f -1 f0f0 f1f1 h h Simpson’s rule: Approximate by Taylor expansion Integrated over x gives 0 Numeriska beräkningar i Naturvetenskap och Teknik