Trying to build a parametric plot based on a NDSolve results, the Mathematica gives an error:

ReplaceAll::reps: {sol} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing

Can someone tell me what's the matter and how can I fix it?

m = 10^-30; 
n = 8;
l = 650*10^-9;
k = 2 Pi/l;
a = 10^-5;
A = 0.01;
T = 10;
vo = (k/a)10^-2;
b = (10^-4)(k/a)^2/2n;

eq = x''[t]-b(1 + t)(Sin[x[t]] - A/k);

sol = 
  NDSolve[{eq == 0, x'[0] == vo, x[0] == 0}, x[t], {t, 0, T}, 
    MaxSteps -> 10^10, AccuracyGoal -> 10, MaxStepSize -> 0.001];

  Evaluate[{x[t], x'[t]} /. sol], {t, 0, T}, 
    AxesLabel -> {"x(t)", "v(t)"}, 
    PlotRange -> {Full, Full}, 
    AspectRatio -> 1/2]
  • $\begingroup$ Are you sure the equation itself is correct? If the options in NDSolve is removed, we'll see NDSolve spits out mxst warning and stops at about 2.234784800684802`*^-8, further check shows the solution seems to increase linearly to about 500 in this region, is this expected behavior? $\endgroup$ – xzczd Apr 11 at 3:31
  • $\begingroup$ Also, the warning reps suggests that the sol = …… line doesn't even calculated successfully. MaxSteps -> 10^10 is a rather demanding setting, are you sure your computer has enough memory to finish calculating? $\endgroup$ – xzczd Apr 11 at 3:45
  • $\begingroup$ Yes, I'm sure the equation itself is correct. But you are right, the computational capabilities of my computer are not enough, it is possible for me to carefully review the initial conditions. Thank! $\endgroup$ – Vadim Apr 11 at 12:10

Looking at the code, you are solving for x[t], but the replacement you use requires you to solve for x (or vice versa). Replace x[t] with x in your `NDSolve' and your replacement will work.

sol = NDSolve[{eq == 0, x'[0] == vo, x[0] == 0}, x, {t, 0, T}, MaxSteps -> 1000, AccuracyGoal -> 10, MaxStepSize -> 0.001];
  • $\begingroup$ Thank you! Now it works. $\endgroup$ – Vadim Apr 11 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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