Ordinary Differential Equations

Created

Used anytime you need to find out how something changes with time (and sometimes space). Differential Equations*: an equation involving the derivative or differentials of the dependent variable Order of a differential equation: the order of the highest derivative in the equation.

Examples

Newton's Law of Cooling Models how temperature changes as it loses heat. "The rate of change in the temperature of an object is proportional to the difference in temperature between the object and room temperature."

ODE : dTobjdt=−α(Tobj−Troom)\frac{dT_{obj}}{dt}= -\alpha(T_{obj} - T_{room}) Solve ODE: Tobj=Troom+(Tinit−Troom)e−αtT_{obj}= T_{room} + (T_{init} - T_{room})e^{-\alpha t}

Swinging of the pendulum Newton's second law for a rotating object can model how the moment of inertia times angular acceleration is equal to the net exteernal torque.

However, that equation is very difficult to solve.

Numerical Solutions

Numerical methods are used to obtain a graph or table of the unknown function.

  • Most methods used to solve ODE are based on truncated Taylor series expansions.

Taylor Series Method

A first order ODE: dy(x)dx=f(x,y)\frac{dy(x)}{dx}= f(x,y), y(x0)=y0y(x_0)= y_0

Solve by estimating the solution at dfferent base points y(xo+h)y(x_o + h), y(x0+2h)y(x_0 + 2h), y(x0+3h)y(x_0 + 3h), ... are trunctaed using gtruncated taylor series expansions.

Trunctaed taylor series expansion: y(xo+h)≈y(x0)+hdydx∣x=x0,y=y0+h22!d2ydx2∣x=x0,y=y0+...+hnn!dnydxn∣x=x0,y=y0y(x_o + h)\approx y(x_0) + h\frac{dy}{dx} \bigg\rvert_{x=x_0, y=y_0} + \frac{h^2}{2!}\frac{d^2y}{dx^2} \bigg\rvert_{x=x_0, y=y_0} + ... +\frac{h^n}{n!}\frac{d^ny}{dx^n} \bigg\rvert_{x=x_0, y=y_0}

  • The nth order Taylor series method uses nth ordertruncated taylor series expansion

First order taylor series method (euler method) y(xo+h)=y(x0)+hdydx∣x=x0,y=y0+o(h2)y(x_o + h) = y(x_0) + h\frac{dy}{dx} \bigg\rvert_{x=x_0, y=y_0} + o(h^2)

Notation: xn=x0+nhx_n = x_0 + nh, yn=y(xn)y_n = y(x_n) dydx∣x=x0,y=y0=f(xi,yi)\frac{dy}{dx} \bigg\rvert_{x=x_0, y=y_0} = f(x_i,y_i) Euler Method:: yi+1=yi+hf(xi,yi)y_{i+1} = y_i + hf(x_i, y_i)

You will be given a problem with the following information: first order ODE: y(x)=f(x,y)y(x) = f(x,y) initial condition: yi=y(x0+ih)y_i = y(x_0 + ih) determine: yi=y(x0+ih)y_i = y(x_0+ih) for i=1,2,...i=1,2,...

Tangent Line Approximation You can approximate a solution to yy by using the tangent like to find out how much the y value differs from the initial t value.

  • If t1t_1 is close enough to t0t_0, then the approximation is good.
  • You can find point t2t_2 using the slope at point t1t_1.
  • Then you plot the points found from each segment and connect with line segments.

yn+1=yn+fn×(tn+1−tn)y_{n+1} = y_n + f_n \times (t_{n+1} - t_n), where fn=f(tn,yn)f_n = f(t_n, y_n)

The error can be found: Percent Relative Error =yexact−yapproxyexact×100= \frac{y_{exact}-y_{approx}}{y_{exact}}\times 100

Heun's Method

A fundamental souorce of error in Eurler's method is that the derivative at the beginingg of the itnerval iss assumed to apply across the entire interval.

The Heun's Method improves the estimate of the slope by determining two derivatives for the interval: initial and end poinnt. Two derivatives are then averaged to obtain an improved estimate of the slope for the entire interval.

Midpoint Method

Also called Improved Polygonmethod. It uses Euler's method to predict a value of y at the midpoint of the inerval.

Runge-Kutt Methods (RK)

Achiev the accuracy of a Taylor series approach without requiring the calculation of higher derivatives.

Matlab

Mathlab recommends ode45 as the first solver for a problem

  • ode45 uses fourth and fifth order Runge-Kuttal formula (Dormand-Prince).
  1. create a m-file fo the dy/dx function (for example, firstode.m)
  2. [x,y]=ode(@firstode,[1,2],-4)
    • Matlab returns two column vectors, the first with values of x an the second with values of y.
  3. Plot with plot(x,y)