Prev: Dynamic Module
Next: Background image sizing
From: Dan Dubin on 30 Sep 2009 05:00 >On Sep 27, 10:16 pm, SlipperyWeasel <slipperywea...(a)gmail.com> wrote: >> I am trying to add random noise to a function inside an NDSolve >> function. Is there a good way to add a "noise function" in my model? > >for example, my system is: x'[t] == x[t] + Sin[t] + v >where v is Gaussian white noise. > >v has to be a continuous function of t in order to use NDSolve on the >ODE, but it also should be uncorrelated. How can I make this a >continuous function while still making it uncorrelated? Your noise function must have a finite correlation time to be realizable, and be a continuous function to work with NDSolve. Here is a continuous random function a(t, dt) consisting of a series of peaks of width dt with random amplitudes amp[n] between +-1 amp[n_] := amp[n] = RandomReal[{-1, 1}]; a[t_, dt_] := amp[Floor[t/dt]] Sin[2 Pi Mod[t, dt]/dt]^2 -- Dan Dubin
From: Daniel Lichtblau on 30 Sep 2009 05:02 SlipperyWeasel wrote: > On Sep 27, 10:16 pm, SlipperyWeasel <slipperywea...(a)gmail.com> wrote: >> I am trying to add random noise to a function inside an NDSolve >> function. Is there a good way to add a "noise function" in my model? > > for example, my system is: x'[t] == x[t] + Sin[t] + v > where v is Gaussian white noise. > > v has to be a continuous function of t in order to use NDSolve on the > ODE, but it also should be uncorrelated. How can I make this a > continuous function while still making it uncorrelated? Make v into a function that returns a random with normal distribution. upper = 2; (* reference example, no noise *) nds1 = NDSolve[{x'[t] == x[t] + Sin[t], x[0] == 0}, x[t], {t, 0, upper}]; v[0] = 0; v[t_] := RandomReal[NormalDistribution[0, .2]] nds2 = NDSolve[{x'[t] == x[t] + Sin[t] + v[t], x[0] == 0}, x[t], {t, 0, upper}]; (* comparison plot *) Plot[{x[t] /. First[nds1], x[t] /. First[nds2]}, {t, 0, upper}] Daniel Lichtblau Wolfram Research
From: DrMajorBob on 30 Sep 2009 05:04 v can't be both continuous AND white noise. The best you can do (I think) is something like this: sigma = 3.5; {start, stop} = {-Pi, Pi}; n = 20; v = Interpolation@ Table[{t, RandomReal(a)NormalDistribution[0, sigma]}, {t, start, stop, (stop - start)/(n - 1)}]; Clear[x] x = x /. First@ NDSolve[{x'[t] == x[t] + Sin[t] + v[t], x[start] == 0}, x, {t, start, stop}]; Plot[{v@t, x@t}, {t, start, stop}] Run that code several times, and you'll see very different results. If sigma is small, though, v will hardly matter at all. Bobby On Tue, 29 Sep 2009 06:36:17 -0500, SlipperyWeasel <slipperyweasel(a)gmail.com> wrote: > On Sep 27, 10:16 pm, SlipperyWeasel <slipperywea...(a)gmail.com> wrote: >> I am trying to add random noise to a function inside an NDSolve >> function. Is there a good way to add a "noise function" in my model? > > for example, my system is: x'[t] == x[t] + Sin[t] + v > where v is Gaussian white noise. > > v has to be a continuous function of t in order to use NDSolve on the > ODE, but it also should be uncorrelated. How can I make this a > continuous function while still making it uncorrelated? > -- DrMajorBob(a)yahoo.com
From: gigabitbucket on 30 Sep 2009 07:33 Slip, I don't have an answer for this, but I do have a problem with the foundations of the question. You're asking for a representation of white noise, continuous in time, but white noise is inherently continuous in frequency too. Then, you propose to solve the de with NDSolve, which often reduces to a step-wise solution. It just doesn't hang together for me. Your problem statement has the strong scent of frequency domain in the first place. Advice is often worth what you pay for it. Fred Klingener On Sep 29, 7:39 am, SlipperyWeasel <slipperywea...(a)gmail.com> wrote: > On Sep 27, 10:16 pm, SlipperyWeasel <slipperywea...(a)gmail.com> wrote: > > > I am trying to add random noise to a function inside an NDSolve > > function. Is there a good way to add a "noise function" in my model? > > for example, my system is: x'[t] == x[t] + Sin[t] + v > where v is Gaussian white noise. > > v has to be a continuous function of t in order to use NDSolve on the > ODE, but it also should be uncorrelated. How can I make this a > continuous function while still making it uncorrelated?
From: SlipperyWeasel on 2 Oct 2009 08:27
On Sep 30, 5:04 am, DrMajorBob <btre...(a)austin.rr.com> wrote: > v can't be both continuous AND white noise. The best you can do (I think)= > is something like this: > > sigma = 3.5; > {start, stop} = {-Pi, Pi}; > n = 20; > v = Interpolation@ > Table[{t, RandomReal(a)NormalDistribution[0, sigma]}, {t, start, > stop, (stop - start)/(n - 1)}]; > Clear[x] > x = x /. First@ > NDSolve[{x'[t] == x[t] + Sin[t] + v[t], x[start] == 0}= , > x, {t, start, stop}]; > Plot[{v@t, x@t}, {t, start, stop}] > > Run that code several times, and you'll see very different results. > > If sigma is small, though, v will hardly matter at all. > > Bobby > > On Tue, 29 Sep 2009 06:36:17 -0500, SlipperyWeasel > > <slipperywea...(a)gmail.com> wrote: > > On Sep 27, 10:16 pm, SlipperyWeasel <slipperywea...(a)gmail.com> wrote: > >> I am trying to add random noise to a function inside an NDSolve > >> function. Is there a good way to add a "noise function" in my model= ? > > > for example, my system is: x'[t] == x[t] + Sin[t] + v > > where v is Gaussian white noise. > > > v has to be a continuous function of t in order to use NDSolve on the > > ODE, but it also should be uncorrelated. How can I make this a > > continuous function while still making it uncorrelated? > > -- > DrMajor...(a)yahoo.com Thanks for the suggestions so far. I had been basically interpolating a random distribution before as most of you suggested. I now have switched to using the Kac-Shinozuka white noise, which gives me hte same results but is quicker and actually continuous. |