Message Boards Message Boards

Calculate MovingAverage of an NDsolve solution?

Posted 8 years ago

I want to average on ndsolve solution but it is not possible. Could anyone help?

Clear["Global`*"]
{d = 0.5, a = Pi, aa = 2, bb = 4, b = 2 Pi, l = 5, k = 1};
ic = x@tbegin == 1;
W = aa (Sin@(a r/l) + d Sin@(b r/l)) + bb;
WW = D[W, r];
f@(r_) = (1/Sqrt@(1 + WW^2));
s@(r_) = -WW/W;
tbegin = 1;
tend = 9000;
interval = {1, 25};

lst = NestWhileList[(# + 
  RandomVariate@
   TruncatedDistribution[interval, 
    StableDistribution[1, 0.3, 0, 0, 1]]) &, tbegin, # < tend &];

F[t_] = Piecewise[{{k, Or @@ #}}, -k] &[# <= t < #2 & @@@ 
Partition[lst, 2]];


 eqn = x'[t] == f@(x@t) (F@(t) + s@(x@t));
sol = NDSolveValue[{eqn, ic}, x, {t, tbegin, tend}, 
MaxSteps -> Infinity];
Plot[sol@t, {t, tbegin, tend}]
First[First[sol]]
h = tbegin : 10 : tend
Plot[sol'[t], {t, tbegin, tend}]
Plot[F[t], {t, tbegin, tend}]
MovingAverage[sol[t], 3]
POSTED BY: s s
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract