So I am solving a differential equation using NDSolve
and plotting the results. But I want to extract the data points in the produced plots to a .txt file. I am aware of the method to extract data from a regular plot of a function, but can't seem to figure out for the NDSolve
. If this is not the way to do it, what other methods are available?
Module[{m = 1, b = 1, g = 9.8, k = 100, time = 5},
s = NDSolve[{m g Cos[ϕ[t]] - k (l[t] - b) ==
m (l''[t] - l[t] ϕ'[t]^2),
-g Sin[ϕ[t]] == l[t] ϕ''[t] + 2 l'[t] ϕ'[t],
l[0] == 1.2,
l'[0] == 0, ϕ[0] == 30*π/180, ϕ'[0] == 0},
{l, ϕ}, {t, 0, time}];
Print[
Plot[Evaluate[l[t] /. s], {t, 0, time}, AxesLabel -> {"t", "l"},
ImageSize -> Small]];
Print[
Plot[Evaluate[ϕ[t] /. s], {t, 0, time},
AxesLabel -> {"t", "ϕ"}, ImageSize -> Small]];
(*data = Cases[Plot[Evaluate[l[t]/.s],{t,0,time},Line[data_]:> data, \
-4*)
Animate[
Graphics[{Point[{0, 0}],
Point[{l[t] Sin[ϕ[t]], -l[t] Cos[ϕ[t]]}],
Line[{{0, 0}, {l[t] Sin[ϕ[t]], -l[t] Cos[ϕ[t]]}}]} /. s,
PlotRange -> {{-2 b, 2 b}, {-2 b, 0.1}}], {t, 0, time}]
]