I'll conclude this sub unit on computational methods
for solving differential equations, with some more general remarks.
So, we've been discussing Euler's method,
- Euler's method is known as a numerical
or computational method for solving the differential equation.
It's computational because it involves doing computations
using, almost always, a computer,
and it's called numerical - that's its may be more traditional term,
because the result of Euler's method is not a formula for a function
but it's a list of numbers, so we call it a numerical method.
Euler's method is quite simple conceptually,
and it gets at the heart of what difference equations are:
- a rule for how something changes,
and that rule is written in terms of the derivative,
- the rate of change, not the function itself.
So, I think if you understand Euler's method,
and may be code it up yourself,
then you really have a good understanding
of what differential equations mean,
so, I definitely recommend if you have some programming skills,
- the language doesn't matter at all,
and you can use a spreadsheet,
to try coding up Euler's method yourself.
I'll list this in the homework for this unit.
So, Euler's method is very nice conceptually,
however it's not very efficient computationally,
so, it's not used much in practice.
Let me say a little bit about how one can improve on Euler's method.
So, to improve on Euler's method,
there are two things one might like to do:
first, there's a family of techniques,
a group of techniques, known as Runge-Kutta methods,
and here's the idea behind them:
I'm not going to go into this in details,
but It's worth mentioning.
So, in Euler's method,
we pretend that the rate of change is constant, over an interval delta t,
and then we have to choose what rate of change
we're going to use, and we just choose the rate of change
at the left part of that interval.
We just take the starting rate of change in that interval
and pretend that it's constant for all of delta t.
Runge-Kutta methods say,
well, rather than using the rate of change at the start of the interval,
what if we use the rate of change at the start of the interval,
and at the end of the interval, and average those two.
That would probably be a more fairer representation
of what's happening in that interval,
or better still, maybe we could sample the rate of change
at three different points along that interval,
and there are different schemes for doing that sampling
and different ways of averaging the different derivatives
that one estimates, but that's the general idea.
Rather than just use one derivative,
sample a couple derivatives, and average those.
So, that's one way to improve on Euler's method.
It's not immediately obvious, but this turns out to be
more efficient, in the sense that, with less computational effort
you can get an equally accurate answer.
The other thing that one typically does
is something called adaptive step size,
and this is: we have the program automatically adjust delta t
on the fly - as it's doing, as it's trying to find a solution.
So, delta t needs to be small
when the derivative is changing rapidly.
We get into trouble with these methods
when we pretend the derivative is
constant over delta t, but it actually changes a lot.
So, if we have a situation where, sometimes,
as time goes on, the derivative is changing rapidly,
and other times, it's not changing rapidly,
then we don't need to use the same delta t.
If the change in derivative is slow,
we can use a large delta t,
when it's fast we need to use a small delta t,
and so these adaptive step-size methods
figure that out on the fly.
I sort of think about it - adaptive step size - as this way,
and this is a rough analogy but it may be gives the right idea,
- imagine you're walking across a landscape,
and you're blindfolded - you can't see.
If the landscape is flat, you can take very big steps,
and you're not going to miss anything,
but if the landscape is very bumpy,
then you'll need to take small steps
to make sure you don't trip or miss something.
So, if you're blindfolded, you might adjust your step size
depending on what you sense the terrain to be.
OK, in any event, the standard way to improve on Euler's method
is to do these two things:
some type of Runge-Kutta method,
and some type of adaptive step size.
Almost all numerical programming environments, that I'm familiar with:
MATLAB, Octave, Maple, Mathematica, Python
- have some sort of built-in Runge-Kutta, adaptive step size solver.
So, perhaps in the form, some of you who have experience
with these different things,
and maybe have solved differential equations before
can post some examples
for how to use these different built-in functions.
OK, lastly, may be just take a look ahead.
So, in the next units, I'll be frequently presenting
solutions to differential equations,
and almost always, the solutions that I present
and show you and discuss will be numerical solutions.
In order to do this course you don't need to
solve differential equations on your own,
you don't need to code up your own algorithms,
you don't need to use other peoples' algorithms,
however, I think it's important that you have
a sense of where these numerical solutions come from.
So, if I show you a solution to a differential equation
you have some idea where that solution came from,
- it's not magic, it's just from using something like
Euler's method - a very simple, but repetitive way
of solving differential equations.