{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Ordinary differential equations - initial value problems\n", "\n", "By the end of this section, you will be able to:\n", "\n", "•\tcreate a Python script to solve first-order initial value problems using the Euler method.\n", "\n", "Differential equations relate one or more functions and their derivatives. Most physical laws in engineering are expressed in terms of differential equations, e.g. Navier-Stokes equations in fluid mechanics and Fourier's Law in heat transfer.\n", "In this section, we are going to focus on ordinary differential equations. An ordinary differential equation contains a function that is dependent on one variable. In particular, we are going to focus on first-order ordinary differential equations.\n", "\n", "## First-order ordinary differential equations\n", "We are going to solve equations of the form\n", "\n", "$$\\frac{dy}{dt}=f(t,y) \\text{ for } a <=t<=b$$\n", " \n", "subject to an initial condition\n", "$$y(a)=y_o$$\n", " \n", "Such problems are known as initial-value problems (IVPs).\n", "\n", "The method we are going to use to solve equations like the above is called Euler's method. It is the easist method for solving these equations.\n", "\n", "Let us divide the interval between $a$ and $b$ into $N$ equal subintervals so that\n", "\n", "$$t_i=a+ih \\text{ for } i=0,1,\\ldots,N$$\n", "\n", "with $h=(b-a)/N$.\n", "\n", "$h$ is known as the step size. Euler's method approximates $y$ by\n", "\n", "$$y_{i+1}=y_i+hf(t_i,y_i), i=0,1,\\ldots,N$$\n", " \n", "The error between the approximate solution and the exact solution is illustrated below.\n", "\"difference\n", "\n", "The error depends on the curvature of the function $y$ and the stepsize $h$. Reducing the step size reduces the error.\n", "\n", "## Exercise\n", "Write a Python script to solve the following initial value problem using the Euler method.\n", "\n", "$$\\frac{dy}{dx}=x, y(0)=0 \\text{ for } 0 <=x<=1$$\n", " \n", "Use a step size $h=0.1$.\n", "\n", "Calculate the error between the approximate solution and exact solution at each step. Output the results in a table.\n", "\n", "Plot the approximate and exact solutions on the same figure.\n", "\n", "Examine the effect of the step-size on the error.\n", "\n", "## Problem 1\n", " \n", "\"difference\n", "\n", "The following first order differential equation, initial value problem, models the current $I$ at time $t$ through a circuit containing a resistance, inductor, and a battery as shown.\n", "\n", "$$L\\frac{dI}{dt}+RI=E$$\n", " \n", "The resistance $R=12\\ \\Omega$ , the inductance $L=4$ H, and the voltage $E=60$ V is constant.\n", "1.\tFind the current at 0.2 s, 0.4 s, and 0.6 s after the switch is closed using the Euler first order explicit method. Use a step size of 0.2.\n", "2.\tFind the percentage error between the numerical methods and the exact solution:\n", "\n", "$$I(t)=5-5e^{-3t}$$\n", " \n", "## Problem 2\n", "A spherical water tank has a radius $R=4$ m and is emptied through a circular hole of radius $r=0.2$ m at the bottom. The top of the tank is open to the atmosphere. The instantaneous water level $h$ in the tank can be determined by the following first order differential equation.\n", "\n", "$$\\frac{dh}{dt}=-\\frac{r^2\\sqrt{2gh}}{2hR-h^2}$$\n", " \n", "where $g=9.81$ m/s/s. The water level at $t=0$ is 6 m.\n", "\n", "Find the water height at 0.2 s, 0.4 s, and 0.6 s using the Euler first order explicit method.\n", "\n", "## Problem 3\n", "A thin hot plate is taken out of an oven and is exposed to the surrounding air. It cools due to heat loss by convection and radiation. The rate at which the plate's temperature $T$ is changing is:\n", "\n", "$$\\frac{dT}{dt}=-\\frac{A}{\\rho V C}\\left(\\sigma \\epsilon \\left(T^4-T_{\\alpha}^4\\right)+h\\left(T-T_{\\alpha}\\right)\\right)$$\n", " \n", "where $A=0.25 \\text{ m}^2$ , $\\rho=300$ kg/m, $V=0.003 \\text{ m}^3$, $C=900$ J/kg/K, $\\epsilon=0.8$, $\\sigma=5.67 \\times 10^{-8} \\text{ W/m}^2\\text{/K}^4$, $h=30 \\text{ W/m}^2\\text{/K}$, and $T_{\\alpha}=298$ K.\n", "\n", "Find the temperature at 5 s, 10 s, and 15 s when the initial temperature is 673 K.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.7" } }, "nbformat": 4, "nbformat_minor": 4 }