1
$\begingroup$

Although there exists this question with an answer I am not able to adopt it to my problem.

I have a 1d Langevin euqation which I solve with NDSolve.

How can I plot the derivative of the solution (see the plot below).

Here is my code:

m = 6.137*10^-13; 
k = 1.5*m; 
stddev = Sqrt[2*k]*Sqrt[m];
whiteNoise = WhiteNoiseProcess[stddev];
randomForce[t_Real] := RandomVariate[whiteNoise[t]];

SeedRandom[1];
s = NDSolve[
   {m*x''[t] + k*x'[t] - randomForce[t] == 0, x[0] == 0, x'[0] == 0}
   , x[t], {t, 0, 50}
   , StartingStepSize -> 10^-3
   , Method -> {"FixedStep", Method -> "ExplicitEuler"
     }
   , MaxSteps -> Infinity
   ];

Plot[x[t] /. s, {t, 0, 50}]

enter image description here

I want to plot x'[t] vs. t.

$\endgroup$

1 Answer 1

1
$\begingroup$
s = NDSolve[{(m*x''[t] + k*x'[t] - randomForce[t]) == 0, x[0] == 0, 
    x'[0] == 0}, x, {t, 0, 50}, StartingStepSize -> 10^-3, 
   Method -> {"FixedStep", Method -> "ExplicitEuler"}, 
   MaxSteps -> Infinity];

Plot[Evaluate[x'[t] /. s], {t, 0, 50}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Great ... so the mistake is that I wrote in NDSolve: x[t] instead of x. The I can write also: Plot[x'[t] /. s, {t, 0, 50}] $\endgroup$
    – mrz
    Commented Apr 6, 2018 at 16:13
  • $\begingroup$ @Lenoil Yes, that's with you needed to do. $\endgroup$
    – zhk
    Commented Apr 6, 2018 at 16:21

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.