{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Numerical Solutions of Two-Point BVPs\n", "\n", "## Overview, Objectives, and Key Terms\n", " \n", "This lesson is all about solving two-point boundary-value problems numerically. We'll apply finite-difference approximations to convert BVPs into matrix systems. Both inhomogeneous cases (e.g., heat conduction with a driving source) and homogeneous (a critical nuclear reactor) will be considered.\n", "\n", "### Objectives\n", "\n", "By the end of this lesson, you should be able to\n", "\n", "- Solve two-point, heterogeneous BVPs.\n", "- Solve two-point, homogeneous BVPs.\n", "\n", "### Prerequisites\n", "\n", "You should already be able to\n", "\n", "- Solve systems of IVPs using Euler's method \n", "- Define one- and two-dimensional arrays using NumPy arrays\n", "- Use `np.linalg.solve` to solve $\\mathbf{Ax = b}$ \n", "\n", "Please review these topics (and resources) as needed.\n", "\n", "### Key Terms\n", "\n", "- Dirichlet boundary condition\n", "- Neumann boundary condition\n", "- Robin (or mixed) boundary condition\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Chopping Up the BVP\n", "\n", "Our focus is again on the second-order BVP\n", "\n", "$$\n", " \\frac{d^2 y}{dx^2} + p(x) \\frac{dy}{dx} + q(x) y(x) = f(x), \\qquad y(a) = y_a, \\qquad y(b) = y_b \\, .\n", "$$\n", "\n", "The goal is to apply numerical differentiation to this equation, leading to a linear system. \n", "\n", "Observe that there are two derivatives in the BVP, one second order, and one first order. There are numerous ways to approximate these by finite differences, but we'll opt for a method with second-order errors. For the first derivative, we already analyzed the central difference:\n", "\n", "$$\n", " \\frac{dy}{dx} = \\frac{y(x+\\Delta)-y(x-\\Delta)}{2\\Delta} + \\mathcal{O}(\\Delta^2) \\, .\n", "$$\n", "\n", "For the second derivative, we saw (but did not analyze) another central difference:\n", "\n", "$$\n", " \\frac{d^2y}{dx^2} = \\frac{y(x+\\Delta)-2y(x)+y(x-h)}{\\Delta^2} + \\mathcal{O}(\\Delta^2) \\, .\n", "$$\n", "\n", "Given these differencing schemes, let us chop the domain $x\\in [a, b]$ into discrete points $x_i = a + \\Delta i,\\, i = 0, 1, \\ldots, n$, where $\\Delta = (b-a)/n$. For all but $i=0$ and $i=n$, we have \n", "\n", "$$\n", " \\frac{y_{i+1} - 2y_i + y_{i-1}}{\\Delta^2}\n", " + p_i \\frac{y_{i+1}-y_{i-1}}{2 \\Delta}\n", " + q_i y_i \n", " = f_i\n", "$$\n", "\n", "where, for example, $y_i = y(x_i)$.\n", "\n", "At the boundaries, we need to be more careful. For the given boundary conditions, our equations are as simple as \n", "\n", "$$\n", " y_0 = y_a\n", "$$\n", "\n", "and\n", "\n", "$$\n", " y_n = y_b \\, .\n", "$$\n", "\n", "The boundary conditions used here are known as *Dirichlet* boundary conditions, in which the unknown function itself is defined at the boundary. *Neumann* boundary conditions specify a value of the *derivative* of the function, e.g., $y'(a) = \\alpha$. *Robin* or *mixed* boundary conditions specify a value of some linear combination of the function and its derivative, e.g., $\\gamma y'(a) + \\beta y(a) = \\alpha$. *Dirichlet* and *Neumann* conditions can be defined in terms of the *Robin* condition using appropriate values of $\\gamma$, $\\beta$, and $\\alpha$.\n", "\n", "\n", "