From d2d99c1c26308619d9d2d23f8946bdb4bf22ef8d Mon Sep 17 00:00:00 2001 From: Kyle Niemeyer Date: Mon, 24 Feb 2020 20:58:27 -0700 Subject: [PATCH] added shooting method example --- _build/quizzes/quiz3-BVPs.html | 43 ++++++++++++++++++++++++++- content/quizzes/quiz3-BVPs.md | 53 ++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/_build/quizzes/quiz3-BVPs.html b/_build/quizzes/quiz3-BVPs.html index 9b2f421..08572da 100644 --- a/_build/quizzes/quiz3-BVPs.html +++ b/_build/quizzes/quiz3-BVPs.html @@ -9,7 +9,7 @@ next_page: url: /contributing.html suffix: .md -search: t r delta equation ri frac infty n lambda begin end ti m b y x sin left right tn k h annular fin dr align eigenvalue pi finite difference temperature radius dt solution quad ldots problem outer described where heat transfer figure center ode location differences recursion c boundary condition replace given prime eigenfunction principal gather cos text therefore associated sample quiz problems bvps method distribution inner d rm radial distance centerline independent variable constant depends coefficient thermal conductivity thickness annulus assuming choose spatial step size img src images png alt style width px figcaptionfigure figcaption representation applies using +search: z t r y delta equation frac begin end ri align infty left right n lambda m solution text ti x b guess sin method tn k h problem annular fin dr boundary eigenvalue prime pi finite difference temperature radius dt where given neq quad ldots forward euler outer described heat transfer step size figure center ode location differences recursion c condition into solve replace eigenfunction principal gather cos bcs therefore associated shooting value target sample quiz problems bvps distribution inner d rm radial distance centerline independent variable constant depends coefficient thermal conductivity thickness annulus assuming choose spatial img src comment: "***PROGRAMMATICALLY GENERATED, DO NOT EDIT. SEE ORIGINAL FILES IN /content***" --- @@ -80,6 +80,47 @@

Solution

a \begin{equation} \lambda_p = \lambda_1 = \frac{\pi}{6} \end{equation}

+

Problem 3: shooting method

Use the shooting method to solve the boundary value problem +\begin{equation} +y^{\prime\prime} - 4y = 0 +\end{equation} +where $y(0) = 0$ and $y(1) = 3$. Find the initial value of $y'$ (meaning, $y'(0)$) that satisfies the given boundary conditions. Use the forward Euler method with a step size of $\Delta x = 0.5$.

+

Solution

First decompose into two 1st-order ODEs: +\begin{align} +z_1' &= y' = z_2 \\ +z_2' &= y'' = 4 z_1 +\end{align} +with BCs $z_1 (0) = 0$ and $z_2 (0) = 3$, we do not know $y'(0) = z_2(0) = ?$

+

Try some guess #1: $y' (0) = 0 = z_2 (0)$, with the forward Euler method: +\begin{align} +z_1 (0.5) &= z_1 (0) + z_2(0) 0.5 = 0 \\ +z_2 (0.5) &= z_2 (0) + \left( 4z_1(0) \right) 0.5 = 0 \\ +z_1 (1.0) &= z_1 (0.5) + z_2(0.5) 0.5 = 0 \\ +z_2 (1.0) &= z_2 (0.5) + \left( 4z_1(0.5) \right) 0.5 = 0 +\end{align} +so for solution 1: $y(1) = 0 \neq 3$.

+

For guess #2: $y' (0) = 2 = z_2 (0)$, with the forward Euler method: +\begin{align} +z_1 (0.5) &= z_1 (0) + z_2(0) 0.5 = 1.0 \\ +z_2 (0.5) &= z_2 (0) + \left( 4z_1(0) \right) 0.5 = 2.0 \\ +z_1 (1.0) &= z_1 (0.5) + z_2(0.5) 0.5 = 2.0 \\ +z_2 (1.0) &= z_2 (0.5) + \left( 4z_1(0.5) \right) 0.5 = 4.0 +\end{align} +so for solution 1: $y(1) = 2 \neq 3$.

+

For guess #3, we can interpolate: +\begin{align} +m &= \frac{\text{guess 1} - \text{guess 2}}{\text{solution 1} - \text{solution 2}} = \frac{0 - 2}{0 - 2} = 1 \\ +\text{guess 3} &= \text{guess 2} + m (\text{target} - \text{solution 2}) = 2 + 1(3-2) = 3 +\end{align} +then, use this guess: +\begin{align} +z_1 (0.5) &= z_1 (0) + z_2(0) 0.5 = 1.5 \\ +z_2 (0.5) &= z_2 (0) + \left( 4z_1(0) \right) 0.5 = 3.0 \\ +z_1 (1.0) &= z_1 (0.5) + z_2(0.5) 0.5 = 3.0 \\ +z_2 (1.0) &= z_2 (0.5) + \left( 4z_1(0.5) \right) 0.5 = 6.0 +\end{align} +so for solution 3: $y(1) = 3$ which is the target.

+

So our answer is $y'(0) = 3$.


 
diff --git a/content/quizzes/quiz3-BVPs.md b/content/quizzes/quiz3-BVPs.md index e4a4b23..b31c012 100644 --- a/content/quizzes/quiz3-BVPs.md +++ b/content/quizzes/quiz3-BVPs.md @@ -86,6 +86,59 @@ b.) The principal eigenvalue is just that associated with $n = 1$: \end{equation} + +## Problem 3: shooting method + +Use the shooting method to solve the boundary value problem +\begin{equation} +y^{\prime\prime} - 4y = 0 +\end{equation} +where $y(0) = 0$ and $y(1) = 3$. Find the initial value of $y'$ (meaning, $y'(0)$) that satisfies the given boundary conditions. Use the forward Euler method with a step size of $\Delta x = 0.5$. + + +### Solution + +First decompose into two 1st-order ODEs: +\begin{align} +z_1' &= y' = z_2 \\ +z_2' &= y'' = 4 z_1 +\end{align} +with BCs $z_1 (0) = 0$ and $z_2 (0) = 3$, we do not know $y'(0) = z_2(0) = ?$ + +Try some guess \#1: $y' (0) = 0 = z_2 (0)$, with the forward Euler method: +\begin{align} +z_1 (0.5) &= z_1 (0) + z_2(0) 0.5 = 0 \\ +z_2 (0.5) &= z_2 (0) + \left( 4z_1(0) \right) 0.5 = 0 \\ +z_1 (1.0) &= z_1 (0.5) + z_2(0.5) 0.5 = 0 \\ +z_2 (1.0) &= z_2 (0.5) + \left( 4z_1(0.5) \right) 0.5 = 0 +\end{align} +so for solution 1: $y(1) = 0 \neq 3$. + +For guess \#2: $y' (0) = 2 = z_2 (0)$, with the forward Euler method: +\begin{align} +z_1 (0.5) &= z_1 (0) + z_2(0) 0.5 = 1.0 \\ +z_2 (0.5) &= z_2 (0) + \left( 4z_1(0) \right) 0.5 = 2.0 \\ +z_1 (1.0) &= z_1 (0.5) + z_2(0.5) 0.5 = 2.0 \\ +z_2 (1.0) &= z_2 (0.5) + \left( 4z_1(0.5) \right) 0.5 = 4.0 +\end{align} +so for solution 1: $y(1) = 2 \neq 3$. + +For guess \#3, we can interpolate: +\begin{align} +m &= \frac{\text{guess 1} - \text{guess 2}}{\text{solution 1} - \text{solution 2}} = \frac{0 - 2}{0 - 2} = 1 \\ +\text{guess 3} &= \text{guess 2} + m (\text{target} - \text{solution 2}) = 2 + 1(3-2) = 3 +\end{align} +then, use this guess: +\begin{align} +z_1 (0.5) &= z_1 (0) + z_2(0) 0.5 = 1.5 \\ +z_2 (0.5) &= z_2 (0) + \left( 4z_1(0) \right) 0.5 = 3.0 \\ +z_1 (1.0) &= z_1 (0.5) + z_2(0.5) 0.5 = 3.0 \\ +z_2 (1.0) &= z_2 (0.5) + \left( 4z_1(0.5) \right) 0.5 = 6.0 +\end{align} +so for solution 3: $y(1) = 3$ which is the target. + +So our answer is $y'(0) = 3$. + ```python ```