I need to export to a txt file the data from the following system of equations:
x'[t] == px[t],
y'[t] == py[t],
px'[t] == x[t]/(2*Sqrt[x[t]^2 + (1 - y[t])^2]),
py'[t] == -0.2 - (1 - y[t])/Sqrt[x[t]^2 + (1 - y[t])^2]
They can be reduced to two equations of x'' and y'', but the number of initial conditions is the same so that's arbitrary.
I successfully solved the system, for example, this way:
sol = NDSolve[{x''[t] == x[t]/(2*Sqrt[x[t]^2 + (1 - y[t])^2]),
y''[t] == -0.2 - (1 - y[t])/Sqrt[x[t]^2 + (1 - y[t])^2],
x[0] == x'[0] == Pi/3, y[0] == y'[0] == 0.5}, {x, y}, {t, -10,
1000}]
Now, how can I export the data from NDSolve
when y[t]==0
AND py[t]>0
? (in a 2-columm table txt file would be great)
y[t]
shows thaty[t]==0
has two solutions on the interval you used. The roots are found usingFindRoot[y[t] /. sol, {t, -1}] FindRoot[y[t] /. sol, {t, 4}]
which yields{t -> -0.655304}
and{t -> 3.66267}
, and by inspecting the plot, only{t -> -0.655304}
satisfiespy[t]>0
. So your final data is just a single 2D point,{x[t], y[t]} /. {t -> -0.655304} /. sol // Chop
, which yields{0.444787, 0}
. I don't quite understand why you need to export this as a TXT file, since it's just a single point, so you could just type it in manually. $\endgroup$