# Mathematica showing error for NDSolve

Manipulate[
Evaluate[sol =
NDSolve[{x''[t] + c*Sin[x[t]] == 0, x'[0] == a[[1]],
x[0] == a[[2]]}, x, {t, 0, tmax}]]; {Dynamic[
Plot[Evaluate[{x[t]} /. sol], {t, 0, tmax}, PlotRange -> All,
PlotStyle -> {Thick, Red}]]}, {c, 0, 10}, {tmax, 0,
20}, {{a, {0, 2.96706}, "initial condition"}, {0, 0}, {10, 10}},
ControlPlacement -> Left]


I want to vary t as well as c... but it gives me an error:

Plot::plld : Endpoints for t in {t,0,FEtmax212} must have distinct machine-precision numerical values.

How can I overcome this problem??

• Have you considered ParametricNDSolve? Jul 16, 2016 at 19:17
• i used ParametricNDSolve, but it's showing error again... "{ParametricNDSolve[{\!(*SuperscriptBox[\"x\", \"[Prime][Prime]\", MultilineFunction->None])[t]==0,\!(*SuperscriptBox[\"x\", \"[Prime]\", MultilineFunction->None])[0]==0,x[0]==2.96706},x,{t,0,0}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing."
– xyz
Jul 16, 2016 at 19:24
• Also, out of curiosity, what are you trying to solve? This is some sort of linear oscillator? Jul 16, 2016 at 19:26
• its a Non linear Oscillator .. which time period depend on theta as well as c...
– xyz
Jul 16, 2016 at 19:38
• Maybe you could give tmax a value distinct from 0, just as it says in the error message? (Note also that the message name for the error clearly indicates it's a problem with Plot, not NDSolve.) Jul 16, 2016 at 20:06

Formatting clean-up and removing redundant Evaluate and Dynamic.

In addition, tmax and c begin at 1 as opposed to 0.

Manipulate[{
sol = NDSolve[{x''[t] + c*Sin[x[t]] == 0,
x'[0] == a[[1]], x[0] == a[[2]]}, x, {t, 0, tmax}];
Plot[Evaluate[{x[t]} /. sol], {t, 0, tmax}, PlotRange -> All,
PlotStyle -> {Thick, Red}]},
{c, 1, 10}, {tmax, 1,20}, {{a, {0, 2.96706}, "initial condition"},
{0, 0}, {10, 10}}, ControlPlacement -> Left]


Solved using Raspberry Pi 3

• @xyz Did this answer your question? Jul 22, 2016 at 2:28

Perhaps this is a possible answer:

Clear[a, b, c, tMax, x, t];
tMax = 20;
sol = ParametricNDSolveValue[{x''[t] + c*Sin[x[t]] == 0, x'[0] == 0,
x[0] == 2.96706}, x, {t, 0, tMax}, {c}]

Plot[Evaluate[Table[sol[c][t], {c, 0, 10, 1}]], {t, 0, tMax},
PlotRange -> All]


With Manipulate also added, perhaps this can be done:

Clear[a, b, c, tMax, x, t];
tMax = 20;
sol = ParametricNDSolveValue[{x''[t] + c*Sin[x[t]] == 0, x'[0] == 0,
x[0] == 2.96706}, x, {t, 0, tMax}, {c}]

Manipulate[
Plot[sol[c][t], {t, 0, tMax}, PlotRange -> All], {c, 0, 10, 1}]

• but i want to see the Variation of the function with changing time as well as c... Where act as an variable.. is it possible to do so ???
– xyz
Jul 16, 2016 at 19:30
• @xyz Does the new edit help? Jul 16, 2016 at 19:33
• Simply Sin[x] is a function of t ..because "x" is a function of [t] ... So Is there any possibility that "t" acts as a variable like c??
– xyz
Jul 16, 2016 at 19:43
• Manipulate does not working ...
– xyz
Jul 16, 2016 at 19:49
• Perhaps I'm failing to understand... It is an ode in t that is being solved. What other variation in time is necessary here besides solving this ode 'in time '? Jul 16, 2016 at 19:49