2
$\begingroup$
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,FE`tmax$$212} must have distinct machine-precision numerical values.

How can I overcome this problem??

$\endgroup$
5
  • $\begingroup$ Have you considered ParametricNDSolve? $\endgroup$
    – dearN
    Jul 16, 2016 at 19:17
  • $\begingroup$ 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." $\endgroup$
    – xyz
    Jul 16, 2016 at 19:24
  • $\begingroup$ Also, out of curiosity, what are you trying to solve? This is some sort of linear oscillator? $\endgroup$
    – dearN
    Jul 16, 2016 at 19:26
  • $\begingroup$ its a Non linear Oscillator .. which time period depend on theta as well as c... $\endgroup$
    – xyz
    Jul 16, 2016 at 19:38
  • 1
    $\begingroup$ 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.) $\endgroup$
    – Michael E2
    Jul 16, 2016 at 20:06

2 Answers 2

2
$\begingroup$

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]

enter image description here

Solved using Raspberry Pi 3

$\endgroup$
1
  • $\begingroup$ @xyz Did this answer your question? $\endgroup$
    – Young
    Jul 22, 2016 at 2:28
-1
$\begingroup$

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]

enter image description here

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}]
$\endgroup$
6
  • $\begingroup$ 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 ??? $\endgroup$
    – xyz
    Jul 16, 2016 at 19:30
  • $\begingroup$ @xyz Does the new edit help? $\endgroup$
    – dearN
    Jul 16, 2016 at 19:33
  • $\begingroup$ 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?? $\endgroup$
    – xyz
    Jul 16, 2016 at 19:43
  • $\begingroup$ Manipulate does not working ... $\endgroup$
    – xyz
    Jul 16, 2016 at 19:49
  • $\begingroup$ 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 '? $\endgroup$
    – dearN
    Jul 16, 2016 at 19:49

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.