Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: NDSolve -- n-body indexing ([[]]) problem

  • To: mathgroup at
  • Subject: [mg112223] Re: NDSolve -- n-body indexing ([[]]) problem
  • From: Themis Matsoukas <tmatsoukas at>
  • Date: Sun, 5 Sep 2010 05:28:22 -0400 (EDT)

The problem is that your differential equations are stochastic. I asked wolfram about it (see email below) using the following as a minimal example (which doesn't work):

g1[t_?NumberQ] := (RandomReal[] - 0.5)*t;
sln = NDSolve[{
   y'[t] == g1[t],
   y[0] == 0
   }, {y}, {t, 0, 1}]
Plot[Evaluate[y /. sln[[1]]][t], {t, 0, 1}, PlotRange -> All, 
 AxesOrigin -> {0, 0}]

Wolfram's answer is basically that you cannot do this NDSolve. Tech support suggested to use RecurrenceTable:

Remove@g1 ; Clear [a, pp];
g1[t_?NumberQ] := (RandomReal[] - 0.5)*t; dt = 0.0001;

pp = RecurrenceTable[{a[n + 1] - a[n] == dt*g1[n], a[0] == 0}, 
   a[n], {n, 1, Round[1/dt]}] ; 
ListPlot[pp, PlotRange -> All]

This, however,  forces you to apply a simple Euler integration and that's unfortunate because you cannot take advantage of advanced integration algorithms (stiff systems, adjustable time steps, etc) unless you code them yourself. I hope that Mathematica will come up with a module similar to NDSolve that is truly numerical, i.e. it would work with tabulated data, not just functions that can be expressed in analytic form.


From: Themis Matsoukas
Date: Wed, 16 Jun 2010 11:42:03 -0500
Subject: [mg112223] Premier Service Help Form
To: support at

Suggestion or Bug:
I want to solve a differential equation of the form,

{y'[t]==G[t], y[0]==y0}

where G[t] is a stochastic function. In the problem I have in mind, the value of G[t] is calculated by running a Monte Carlo simulation, so its actual value at each point is subject to some noise. However, I found out that NDSolve does not accommodate ODEs whose right-hand side contains stochastic terms. In a minimal example (which I am attaching), the definition of G is

G[t_] := (RandomReal[] - 0.5) t;

When G is used inside NDSolve, it seems that the random number is calculated just once and not each time an evaluation of G[t] is called for. That is, NDSolve treats G as if

G[t_] := A t

where A is a constant  that is randomly picked at the beginning of the calculation. Is there a way to force NDSolve to use the actual values that would returned by the delayed assignment in the definition of G?


Themis Matsoukas

Hello Mr. Matsoukas,

Thank you for the email. Please refer to the attached notebook. Essentially
NDSolve is not well suited to solve Stochastic type differential equations.
The use of RecurrenceTable is a more appropriate option. 


Paritosh Mokhasi, Ph.D.
Technical Support
Wolfram Research, Inc.

  • Prev by Date: Re: <Null> while building lists
  • Next by Date: Re: FindRoots?
  • Previous by thread: NDSolve -- n-body indexing ([[]]) problem
  • Next by thread: Re: NDSolve -- n-body indexing ([[]]) problem