21.04.2015 Views

The Computable Differential Equation Lecture ... - Bruce E. Shapiro

The Computable Differential Equation Lecture ... - Bruce E. Shapiro

The Computable Differential Equation Lecture ... - Bruce E. Shapiro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

154 CHAPTER 8. BOUNDARY VALUE PROBLEMS<br />

We will modify the Euler program slightly to take the number of mesh points and<br />

the two boundary points – rather than the step size – as parameter. This is because<br />

we want to force the problem to stop at the second boundary point. <strong>The</strong> following<br />

code will return a single Euler solution for the variable u (we don’t really care about<br />

v since it was not in the original problem).<br />

EulerIVP[f , ya , a , b , n ] :=<br />

Module[{ t, y, h, solution},<br />

h = (b - a)/n;<br />

solution = {{a, ya[[1]]}};<br />

y = ya;<br />

For[t = a, t < b, t += h,<br />

y = y + h*f[t, y];<br />

AppendTo[solution, {t + h, y[[1]]}];<br />

];<br />

Return[solution];<br />

]<br />

Suppose we want to estimate the solution using a mesh with 100 intervals. <strong>The</strong>n<br />

our first guess would be obtained with<br />

f[t , u , v ] := {v, u/(t*t) - v/t}<br />

EulerIVP[f, 1, 0, 1, 2., 100]<br />

which will return<br />

{{1, 1}, {1.01,1}, {1.02, 1.0001},...,{2.,1.25041}}<br />

where the intervening values have been omitted. <strong>The</strong> very last value is what we are<br />

interested in: our first guess gives u(2) (0) = 1.25041. Our goal is to iterate on this<br />

value: if we have two guesses at c and the corresponding two guess at u(2), we can<br />

use linear interpolation to make a third guess:<br />

m (i) = u(b)(i) − u(b) (i−1)<br />

c (i) − c (i−1) (8.9)<br />

c (i+1) = c (i) +<br />

u(b) − u(b)(i)<br />

m<br />

(8.10)<br />

<strong>The</strong> problem is that we don’t have a good second estimate for c, so we pick one<br />

arbitrarily, namely<br />

c (1) = c (0) + 1 = 1 (8.11)<br />

<strong>The</strong>n<br />

returns<br />

EulerIVP[f, 1, 1, 1, 2., 100]<br />

{{1, 1}, {1.01,1.01}, {1.02, 1.02},...,{2.,2}}<br />

Math 582B, Spring 2007<br />

California State University Northridge<br />

c○2007, B.E.<strong>Shapiro</strong><br />

Last revised: May 23, 2007

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!