Wolfram Blog
Daniel Lichtblau

Demonstrations Pick: Numerical ODE Methods You Might Use for Your Classroom. Or Your Homework.

April 8, 2008 — Daniel Lichtblau, Scientific Information Group

I would like to point to a recent member of The Wolfram Demonstrations Project: Numerical Methods for Differential Equations.

Numerical Methods for Differential Equations

It was submitted a few weeks ago, and I rather liked it because it illustrated several basic numerical approaches to solving a first-order differential equation. Without much fuss this quickly brings one into numerical analysis, approximation methods, and other polysyllabic topics important to engineering, math, and related fields.

As it was making the rounds through our review process, I received one of those phone calls that parents know all too well: the college student emergency homework appeal. I picked up the phone.

“Why Booboo,” I sez, “What’s up?”

“Listen, fatso, I need some help with my homework.” Yes, she really calls me that. Kids can be cruel.

Turns out she had to do a derivation and some computations for her DiffEq class. I had been forewarned about the derivation, and gave a few hints. The computation was, I thought, cute. It goes like this. We have the differential equation y‘=-y (your garden-variety exponential decay), initial condition y(0)=1. We are using Euler’s method to approximate a solution between x=zero and one. The students are to subdivide into two, three, four pieces, (more if need be), see what values for y they have at x=1, and try to guess what the sequence is as a function of n subdivisions.

Now most students will whip out a calculator, and if it does not do these using rationals, they won’t really get the idea. She had done the first couple by hand so at least she was still in contention. I asked what she had so far and she said with two divisions it gives 1/4 and with three it gives 8/27. I’m enough of a math geek to see where it was heading, even made sure my answer would go to 1/e in the limit. I can do this while making with the small talk (kids don’t know these tricks). Then I told her (I had to be firm here):
(a) I am not doing this for you.
(b) You need to use rational numbers again if you want to see what it is doing.

Eventually she realized she was not going to beat the answer out me, and pouted off either to go do the work herself, or else sweet-talk it out of some hapless classmate. Fathers need not know from such details.

Meanwhile, I looked up and saw a lightbulb had gone on over my head. Low wattage, but one of those swirly fluorescents so still fairly bright (yes, even imaginary scenarios have to evolve with technology). I realized I had been looking at a Demonstration that already had the makings of this computation, except it did not show the values calculated at the discrete segment endpoints. We asked the author if adding that capability might be a possibility. Author said “sure” (and was happy to learn about Tooltip functionality). We got the revised version and set to tinkering with it.

At this point I have to admit that there were some complications, and they go outside the realm for which this Demonstration was really intended. For one thing, not all of the functions give rational values at the segment endpoints. Some that do might give rationals with huge numerators and denominators, and the computation of these can be really slow compared to the machine-arithmetic approximations that are just fine for display purposes. So it took a bit of playing around, disabling those exact computations in cases where they were deemed not useful and/or too slow. We made a few other changes to make sure the Demonstration would behave well at all control settings. So if it seems to be either a bit sluggish or not giving the control range you would like, chances are it’s my fault and the author had better things in mind.

When the dust settled we had a published Demonstration. It was now two weeks after the homework had been handed in. But I sent the link to my daughter. She liked the Demonstration. Then huffed a bit that the problem had been easy (such petulance in one’s own progeny can be amusing), except she didn’t like doing that computation by hand.

But now you do not need to. Set the y‘ control to -y, and method to “explicit Euler”. Set endpoint controls a to 0 and b to 1. Set initial value y0 to 1. Gingerly move the steps slider to 4. Voila. Now place your cursor over the maroon dot at the end of the rightmost approximating segment, press the mouse button, and read off coordinates: (1, 81/256).

So… what will it give for n segments?

Posted in: Education
Leave a Comment

No Comments




Leave a comment

Loading...

Or continue as a guest (your comment will be held for moderation):