Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
4Activity
0 of .
Results for:
No results containing your search query
P. 1
Lecture 4: Introduction to Numerical Methods for ODEs

Lecture 4: Introduction to Numerical Methods for ODEs

Ratings: (0)|Views: 267 |Likes:
Published by aroobadilawer
mathematica
mathematica

More info:

Published by: aroobadilawer on Oct 15, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

07/20/2010

pdf

text

original

 
Lecture 4: Introduction to numerical methods for ODEs
We have learnt to solve ODEs with
Mathematica
, and for that purpose we don't need to know much about what
Mathemat-ica
actually does to solve ODEs. However,
Mathematica
is not the final answer to all problems. The solution of verycomplex problems, such as three dimensional fluid dynamics on very large computational grids, may require a C or Fortrancode to achieve the necessary memory and computational efficiency. We will therefore venture a little into the world of numerical methods for the solution of ODEs, and still use
Mathematica,
as a learning tool, to program those methods.
Solving an ODE of order N is equivalent to performing N integrations. As the integral of a function corresponds to thesurface area below the function, each integration involves a computation of that area. The accuracy of a numerical methodfor solving ODEs is therefore the accuracy with which we compute that surface area. For initial value problems, for exam-ple with time as the free variable, the basic idea of most numerical methods is to discretize time into a number of smallintervals, and advance the solution step by step. In other words, we are computing that surface area below the function bysubdividing it into pieces. Each step of the computation then needs to evaluate the area of one of those pieces. The accuracyof the numerical solution increases as the time-step size decreases.The discretization of the problem is equivalent to defining a map that corresponds to the original function. Maps are knownto present chaotic solutions at lower phase-space dimensionality than functions. Two dimensional maps can be chaotic,while differential equations must explore at least a 3 dimensional phase space to exhibit chaotic behavior. That shouldimmediately alert you of a problem for our numerical solutions based on a discretization of the problem: You may start witha system that is not chaotic, and design a numerical scheme corresponding to a map that is instead chaotic, for certain valuesof the parameters or initial conditions. This is far from a simple academic discussion. The
stability
of numerical methods tosolve ODEs is a major concern, especially when advancing in time the solution of partial differential equations, where theother variable (e.g. space dimensions) have also been discretized.We will discuss here the Euler and the Predictor-Corrector schemes. The final problem of this week homework is animplementation of a centered-difference scheme. 
The Euler Method
Let's not be too ambitious for now and consider the most simple first-order ODE:
 
„ 
v
ÅÅÅÅÅÅÅ
„ 
=
H
,
v
L
,
v
H
0
L
=
v
o
.
As we said above, the basic idea is to discretize the time into small intervals of size
D
t: 
n
=
n
D
,
n
=
0,1,2,3,....
Discretizing the problem means that, while the integral of the original function could be evaluated at any real value of time,we now instead evaluate the integral of the function only at a finite number of time steps: 
 
 
Ÿ 
t0t1
 f 
H
,
v
H
LL
dt
Ø
Ÿ 
t1t2
 f 
H
,
v
H
LL
dt
Ø
...
 
.....
Ø
Ÿ 
tn
-
1tn
 f 
H
,
v
H
t0
LL
dt
 
In this way we map v1
Ø
v2, v2
Ø
v3, ......vn-1
Ø
vn. Designing the numerical scheme corresponds to defining such map.The integrals are not trivial to compute, because f depends on the unknown v, which we have not solved yet for the valuesof time covered by the next integral. The way in which we approximate f over the next time interval defines our numericalmethod.In Euler's method we simply take f = constant in the whole interval!Each step of the integration of the simple first order ODE is 
Ÿ 
n
-
1
n
 
„ 
v
ÅÅÅÅÅÅÅ
„ 
„ 
 
=
v
H
n
L
-
v
H
n
-
1
L
=
Ÿ 
n
-
1
n
 f 
H
,
v
H
LL
„ 
.
If we impose that f = constant in the whole time interval, we can simply choose its initial value, which can be evaluated because the initial value of v is known from the previous step or from the initial condition: 
Ÿ 
n
-
1
n
 f 
H
,
v
H
LL
„ 
ºD
t
H
n
-
1
,
v
H
n
-
1
LL
+
O
H
D
2
L
.
The error in this approximation scales as
D
2
(same notation as in power series expansions). You can easily verify the order of approximation of that integral with a Taylor expansion.With this approximation, the solution of each time step becomes:
v
H
n
L
=
v
H
n
-
1
L
+D
t f  
H
n
-
1
,
v
H
n
-
1
LL
+
O
H
D
2
L
Which is Euler's method. Now you can really see what the discrete map looks like: It is recursion relation. Now you will suddenly appreciate the advantage of testing a numerical scheme like this one with
Mathematica
, because
athematica
has a trivial way of defining a recursion relations: You basically write them down as they are!!
t
@
n_ 
D
:
=
n
D
t;v
@
n_ 
D
:
=
v
@
n
-
1
D
+ D
t f
@
t
@
n
-
1
D
, v
@
n
-
1
DD
;v
@
0
D
:
=
v0
IMPORTANT: The delayed evaluation in the recursion relation is necessary.COMPUTER EXAMPLE 1: Solve a simple ODE, play with different time steps, plot the function. Stress the importance of the /; condition and its parenthesis, stress the importance of the extra = , in order to remember the value of each recursionstep, so
 Mathematica
does not recompute the whole recursion every time.
2
Lecture4.nb 
 
t
@
n_ 
D
:
=
n
D
t;v
@
n_ 
D
:
=
H
v
@
n
D
=
v
@
n
-
1
D
+ D
t f
@
t
@
n
-
1
D
, v
@
n
-
1
DDL ê
;n
>
0 && n
œ
Integers;v
@
0
D
:
=
v0
D
t
=
0.2;f
@
t_, v_ 
D
=
t
-
v;v0
=
0;solution
=
Table
@8
t
@
n
D
, v
@
n
D<
,
8
n, 0, 4
ê
D
t
<D
88
0, 0
<
,
8
0.2, 0
<
,
8
0.4, 0.04
<
,
8
0.6, 0.112
<
,
8
0.8, 0.2096
<
,
8
1., 0.32768
<
,
8
1.2, 0.462144
<
,
8
1.4, 0.609715
<
,
8
1.6, 0.767772
<
,
8
1.8, 0.934218
<
,
8
2., 1.10737
<
,
8
2.2, 1.2859
<
,
8
2.4, 1.46872
<
,
8
2.6, 1.65498
<
,
8
2.8, 1.84398
<
,
8
3., 2.03518
<
,
8
3.2, 2.22815
<
,
8
3.4, 2.42252
<
,
8
3.6, 2.61801
<
,
8
3.8, 2.81441
<
,
8
4., 3.01153
<<
a
=
ListPlot
@
solution, PlotStyle
Ø
PointSize
@
0.015
D
,DisplayFunction
Ø
Identity
D
;b
=
Plot
@
E^
-
t
+
t
-
1,
8
t, 0, 4
<
, DisplayFunction
Ø
Identity
D
;Show 
@
a, b, DisplayFunction
Ø
$DisplayFunction
D
;
1 2 3 40.511.522.53
vEuler
=
Interpolation
@
solution
D
InterpolatingFunction
@88
0., 4.
<<
,
<>
D
Lecture4.nb 
3

Activity (4)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads
ChinmayKrishna liked this
wave_rider liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->