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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

84 CHAPTER 4. IMPROVING ON EULER’S METHOD<br />

<strong>The</strong> iteration formula is<br />

y (i+1)<br />

n<br />

= y (i)<br />

n<br />

= y (i)<br />

n<br />

− g(y(i) n )<br />

g ′ (y n (i) )<br />

− y(i) n<br />

− y n−1 − hf(t, y (i)<br />

n )<br />

1 − hf y (t, y (i)<br />

n )<br />

For the vector initial value problem, the corresponding iteration formula is<br />

y (i+1)<br />

n<br />

= y (i)<br />

n<br />

(<br />

− I − h ∂f ) −1 ( )<br />

y n<br />

(i) − y n−1 − hf(t n , y n (i) )<br />

∂y<br />

(4.109)<br />

(4.110)<br />

(4.111)<br />

Again, it is not generally efficient to calculate a matrix inverse; it is better to solve<br />

a linear system of equations. We can reformulate the last equation as<br />

(<br />

y (i+1)<br />

n<br />

) (<br />

− y n<br />

(i) I − h ∂f ) (<br />

)<br />

= − y n<br />

(i) − y n−1 − hf(t n , y n (i) )<br />

∂y<br />

(4.112)<br />

We can solve the linear system for δ = y n<br />

(i+1)<br />

δ − y n (i) .<br />

− y (i)<br />

n<br />

and then calculate y (i+1)<br />

n =<br />

We then have the following Mathematica Implementation.<br />

=⇒<br />

=⇒<br />

=⇒<br />

=⇒<br />

=⇒<br />

BackwardEulerNewtonsMethod[f , {t0 , y0 }, h , tmax , tol :0.003,<br />

nmax :5] :=<br />

Module[{ t, y, n, time, yval, yvaln, yvalp, delta, r, J, JV,<br />

fv},<br />

r = {{t0, y0}};<br />

yval = y0;<br />

J = D[f[t, y], {y, 1}];<br />

For[time = t0, time < tmax, time += h,<br />

(***** calculate first guess at next grid point *****)<br />

fv = f[time+h, yval];<br />

JV = J /. {t -> time+h, y -> yval};<br />

yvaln =(-yval + h (-fv + JV *yval))/(-1+h*JV);<br />

(***** iterate using Newton’s method *****)<br />

For[i = 1, i ≤ nmax, i++,<br />

yvalp = yvaln;<br />

(***** update derivative *****)<br />

JV = J /. {t -> time+h, y -> yvalp};<br />

(***** update function value *****)<br />

fv = f[time+h, yvalp];<br />

(***** Newton Iteration Formula *****)<br />

yvaln=(yval + h(fv - JV* yvalp))/(1-h*JV);<br />

(***** Within desired tolerance? *****)<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!