2
$\begingroup$

I have a differential equation:

$$\frac{dx}{dt}=\operatorname{sech}(x-1)$$

I want to add noise to it and try to solve it numerically, but it seems that I am programming something wrong, because there is no noise. I am trying to do this by adding a random number.

ClearAll["Global`*"]

pars = {α = 1, β = 1/20, γ = 1, 
  h = 1, ω = 2 Pi 1/2, μ = 1, xs = -1, xe = 1}

f = Sech[x[t] - xe]

sys = NDSolve[{x'[t] == 
    ArcTan[1 D[f, x[t]]] + RandomReal[{-1/10, 1/10}], 
   x[0] == xs}, {x}, {t, 0, 500}]

Plot[{Evaluate[x[t] /. sys], xe}, {t, 0, 10}, PlotRange -> All, 
 PlotPoints -> 40]
$\endgroup$
8
  • $\begingroup$ NDSolve[] does not have a Hold* attribute, so RandomReal[{-1/10, 1/10}] gets evaluated at once. $\endgroup$ Jan 26, 2021 at 6:03
  • $\begingroup$ @J.M. How to solve the problem? $\endgroup$
    – dtn
    Jan 26, 2021 at 6:05
  • $\begingroup$ Maybe add noise=RandomReal[{-1/10, 1/10}] right after the definition of f and then sys = NDSolve[{x'[t] == ArcTan[1 D[f, x[t]]] + noise, x[0] == xs}, {x}, {t, 0, 500}]? $\endgroup$ Jan 26, 2021 at 7:08
  • $\begingroup$ @DanieleBinosi No, it doesn't work $\endgroup$
    – dtn
    Jan 26, 2021 at 7:13
  • 1
    $\begingroup$ A related question. $\endgroup$ Jan 26, 2021 at 8:15

1 Answer 1

4
$\begingroup$

One way to make random noise over the range t = 0 to 10:

ttab=Table[i/10,{i,0,100}];

Noisetab=Table[Random[Real, {-1/10, 1/10}], {101}]

Noise=Interpolation[Table[{ttab[[i]],Noisetab[[i]]},{i,101}]]

Plot the noise.

Plot[Noise[t],{t,0,10}]

enter image description here

You can then add Noise[t] to your differential equation. If you want more or fewer points in your noise or a different range, you can make adjustments.

Editing your NDSolve statement and plotting:

sys = NDSolve[{Derivative[1][x][t] == ArcTan[1*D[f, x[t]]] + Noise[t], x[0] == xs}, {x}, {t, 0, 10}]

Plot[{Evaluate[x[t] /. sys], xe}, {t, 0, 10}, PlotRange -> All, PlotPoints -> 40]

enter image description here

$\endgroup$
3
  • $\begingroup$ Nice answer. Thank you! $\endgroup$
    – dtn
    Jan 26, 2021 at 8:45
  • $\begingroup$ I did it a little differently: x'[t] == ArcTan[1 D[f, x[t]]] + k Sin[RandomReal[{-100, 100}] t] Sin[ RandomReal[{-100, 100}] t] Sin[RandomReal[{-100, 100}] t] $\endgroup$
    – dtn
    Jan 26, 2021 at 9:51
  • 1
    $\begingroup$ That works too. I am sure there are many ways to randomize functions of time that are suitable. $\endgroup$
    – Bill Watts
    Jan 26, 2021 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.