|
|
| Author |
Message |
Maarten van Reeuwijk science forum beginner
Joined: 05 May 2005
Posts: 25
|
Posted: Thu Mar 23, 2006 9:46 pm Post subject:
The Maple's integrator - but now numerical
|
|
|
When I integrate a system numerically, say x' = x, by using dsolve with a
size N output array, it does it beautifully. Say the result is stored in
vector xx. Furthermore, when I integrate this system from halfway on, by
using x(0) = xx[N/2+2], and store the output in xx2, the results look
beautiful as well. However, when I look at the difference delta = xx2 - xx
(corrected for differences in indices, naturally), it behaves very curious.
I would expect that delta=0, as I use a value that Maple calculates itself
to restart the integration. But instead, it jumps to 10^-3 in the first
output step and oscillates, with increasing amplitude due to the
exponential growth. The Maple code below shows this strange behavior - I
apologize that it is so much but it was the shortest I could make it.
Does anyone know where this is coming from and how it can be avoided? I am
trying to calculate Lyapunov exponents but with oddities like this that is
not such an easy task :-)
TIA, Maarten
---
restart; with(DEtools): with(plots):
Digits := 20;
eq := diff(x(t), t) = x(t) ;
ic := x(0) = x0;
sol := simplify(rhs(dsolve([eq, ic], x(t))));
T := 20;
x0 := 1;
N := 1000; dt := T / N;
timesteps := Array(1..N, i -> (i-1)*dt);
sol_arr := dsolve({eq, ic}, x(t), type=numeric,maxfun=-1,output=timesteps):
soldd:=sol_arr[2,1]:
tt := soldd[1..N, 1]:
xx := soldd[1..N, 2]:
ic := x(0) = xx[N/2+1];
timesteps := Array(1..N/2, i -> (i-1)*dt);
sol_arr := dsolve({eq, ic}, x(t), type=numeric,maxfun=-1,output=timesteps):
soldd:=sol_arr[2,1]:
xx2 := soldd[1..N/2, 2]:
pp := seq([tt[i], xx[i]], i=1..N):
pp2 := seq([tt[i+N/2], xx2[i]], i=1..N/2):
logplot([sol, [pp], [pp2]], t=0..T, legend=["exact", "num", "num halfway"]);
delta := xx2 - xx[N/2+1..N]:
delta[1..10];
pp := seq([tt[N/2+i], delta[i]], i=1..N/2):
plot([pp], t=0..T);
pp := seq([tt[N/2+i], abs(delta[i])], i=1..N/2):
logplot([pp]);
--
===================================================================
Maarten van Reeuwijk dept. of Multiscale Physics
Phd student Faculty of Applied Sciences
maarten.ws.tn.tudelft.nl Delft University of Technology |
|
| Back to top |
|
 |
Maarten van Reeuwijk science forum beginner
Joined: 05 May 2005
Posts: 25
|
Posted: Mon Mar 27, 2006 3:35 pm Post subject:
Re: The Maple's integrator - but now numerical
|
|
|
Preben Alsholm wrote:
| Quote: | The difference decreases dramatically if you choose method=gear, a
single step method.
|
Thank you, that does improve the error amplitude. However, the growth of
differences still is quite erratic, featuring jumps. Only when I use a
integration method with fixed time-step, such as method=classical[rk4], do
I get the expected behavior that the difference delta=0 for all t.
Does anyone know how adaptive time stepping can cause such bizarre behavior?
Maarten
| Quote: | Preben Alsholm
Maarten van Reeuwijk wrote:
When I integrate a system numerically, say x' = x, by using dsolve with a
size N output array, it does it beautifully. Say the result is stored in
vector xx. Furthermore, when I integrate this system from halfway on, by
using x(0) = xx[N/2+2], and store the output in xx2, the results look
beautiful as well. However, when I look at the difference delta = xx2 -
xx (corrected for differences in indices, naturally), it behaves very
curious.
I would expect that delta=0, as I use a value that Maple calculates
itself to restart the integration. But instead, it jumps to 10^-3 in the
first output step and oscillates, with increasing amplitude due to the
exponential growth. The Maple code below shows this strange behavior - I
apologize that it is so much but it was the shortest I could make it.
Does anyone know where this is coming from and how it can be avoided? I
am trying to calculate Lyapunov exponents but with oddities like this
that is not such an easy task :-)
TIA, Maarten
---
restart; with(DEtools): with(plots):
Digits := 20;
eq := diff(x(t), t) = x(t) ;
ic := x(0) = x0;
sol := simplify(rhs(dsolve([eq, ic], x(t))));
T := 20;
x0 := 1;
N := 1000; dt := T / N;
timesteps := Array(1..N, i -> (i-1)*dt);
sol_arr := dsolve({eq, ic}, x(t),
type=numeric,maxfun=-1,output=timesteps): soldd:=sol_arr[2,1]:
tt := soldd[1..N, 1]:
xx := soldd[1..N, 2]:
ic := x(0) = xx[N/2+1];
timesteps := Array(1..N/2, i -> (i-1)*dt);
sol_arr := dsolve({eq, ic}, x(t),
type=numeric,maxfun=-1,output=timesteps): soldd:=sol_arr[2,1]:
xx2 := soldd[1..N/2, 2]:
pp := seq([tt[i], xx[i]], i=1..N):
pp2 := seq([tt[i+N/2], xx2[i]], i=1..N/2):
logplot([sol, [pp], [pp2]], t=0..T, legend=["exact", "num", "num
halfway"]); delta := xx2 - xx[N/2+1..N]:
delta[1..10];
pp := seq([tt[N/2+i], delta[i]], i=1..N/2):
plot([pp], t=0..T);
pp := seq([tt[N/2+i], abs(delta[i])], i=1..N/2):
logplot([pp]);
|
--
===================================================================
Maarten van Reeuwijk dept. of Multiscale Physics
Phd student Faculty of Applied Sciences
maarten.ws.tn.tudelft.nl Delft University of Technology |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Thu Jan 08, 2009 2:01 pm | All times are GMT
|
|
Guitar Lessons | Loans | Facebook Proxy | Fast Loans | Free eBooks Download
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
Other DeniX Solutions sites:
Electronics forum |
Medicine forum |
Unix/Linux blog |
Unix/Linux documentation |
Unix/Linux forums
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|