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.

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

We could implement this in Mathematica as follows:<br />

=⇒<br />

=⇒<br />

=⇒<br />

=⇒<br />

=⇒<br />

BackwardEulerFP[f , {t0 , y0 }, h , tmax , tol , imax ] :=<br />

Module[{ time, yval, yvaln, yvalp, delta, eps, r},<br />

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

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

(***** Do next Backward Euler Step *****)<br />

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

(***** Do Fixed Point Iteration on y *****)<br />

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

yvalp = yvaln;<br />

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

delta = yvaln - yvalp;<br />

If[Abs[delta] < tol, Break[]];<br />

];<br />

yval = yvaln;<br />

AppendTo[r, {time + h, yval}]; ];<br />

Return[r]; ]<br />

We know that equation 4.103 is only guaranteed to have a fixed point, and iteration<br />

is only guaranteed to converge, if it is a contraction mapping. This requires<br />

‖hf y (t, y)‖ < 1. Convergence becomes rapid when ‖hf y (t, y)‖ y0, t -> t0;<br />

If[Abs[JV] >= 1,<br />

Print["This problem is ill-conditioned for fixed point iteration."];<br />

Return[$Failed];<br />

];<br />

This calculates the scalar Jacobian analytically, and places the formula in the<br />

variable J , and then calculates the numerical value of the Jacobian in the variable<br />

JV . If the magnitude of the Jacobian is larger than or equal to one, then fixed point<br />

iteration is not guaranteed to work, so the program aborts. Later in the algorithm,<br />

after the next step is calculated, one also needs to test to see if the problem has<br />

entered an ill-conditioned region. To do this one can recalculate the value of the<br />

Jacobian, using the analytic formula already determined, merely substituting the<br />

current values of y and t.<br />

JV = J/.y-> ynext, t-> time<br />

If[Abs[JV]>= 1 ...<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!