Question

I have a question about NDSolve function in Mathematica. I have an oscillator defined by these two equations:

x' = v
v' = -x - u*v^3

where u is some constant.

How to create an NDSolve that resolves this? I tried following code (it has to depend on time) but it doesnt work:

eq1 = x'[t] == v;
eq2 = v' == -x[t] - u*v^3;
eq3 = x[0] == 2;

(initial displacement is 2m).

s = NDSolve[{eq1, eq2, eq3}, x, {t, 0, 30}]

Thank you very much...

Was it helpful?

Solution

You need to observe that the first equation once differentiated with respect to t can be used to substitute for v[t]. But then the second equation becomes a ODE of second order and requires to be supplied with another extra initial condition. We will give

v[0]==x'[0]==some number

Then after solving this ODE for x you can recover v[t]==x'[t] I give you the solution in term of a Manipulate so that geometrically the situation becomes clear to you.

(* First equation *)
v[t] = x'[t];
(* 
   Differentiate this equation once and substitute 
   for v[t] in the second equation
*)
Manipulate[
With[{u = Constant, der = derval}, 
     res = NDSolve[{x''[t] == -x[t] - u*x'[t]^3, x[0.] == 2,x'[0.] == der},
     x, {t, 0., 30.}] // First; 
     Plot[Evaluate[{x[t], v[t]} /. res], {t, 0, 30}, PlotRange -> All,
     Frame -> True,Axes -> None, ImageSize -> 600]
   ],
{{Constant, 0.,TraditionalForm@(u)}, 0.,3, .1},
{{derval, -3., TraditionalForm@(v[0] == x'[0])}, -3, 3, .1}
]

enter image description here

Hope this helps you but next time before you ask you need to brush up the theory first as you can see the question you asked concerns very basic and elementary Mathematics not Mathematica programming. Good luck!!

OTHER TIPS

You need to specify a numeric value for your u as well as an initial condition for v[t] :

u=1.0;
solution=NDSolve[{x'[t]==v[t], v'[t]==-x[t]-u v[t]^3,x[0]==2,v[0]==-1},{x,v},{t,0,1}]

Plot[{solution[[1,1,2]][t],solution[[1,2,2]][t]},{t,0,1}]

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top