I want to solve the ode and plot the solution v[x]
for different values of parameter a
where x=2000
(for just any fixed position x or event at x). By looking at examples of EventLocator
available online i tried to write the code as:
data = Table[Reap[
soln =
NDSolve[{I D[v[x], x] == (0.4 + a)*v[x], v[0] == 1}, {v[x]}, {x, 0, 2000},
Method -> {"EventLocator",
"Event" -> Abs[v[x]]^2,
"EventCondition" -> x == 1000,
"EventAction" :> Sow[{a, Evaluate[Abs[v[x]]]^2 /. soln}]}]][[2, 1]],
{a, -1, 0, 0.3}]
But it does not give data file i wanted to grab as{a,[Abs[v[x]]^2}
. instead it shows:
Part::partw: Part 1 of {} does not exist. >>
Part::partw: Part 1 of {} does not exist. >>
Part::partw: Part 1 of {} does not exist. >>
General::stop: Further output of Part::partw will be suppressed during this calculation. >>{{{{v[x]->InterpolatingFunction[{{0.,2000.}},<>][x]}},{}}[[2,1]],
{{{v[x]->InterpolatingFunction[{{0.,2000.}},<>][x]}},{}}[[2,1]],
{{{v[x]->InterpolatingFunction[{{0.,2000.}},<>][x]}},{}}[[2,1]],
{{{v[x]->InterpolatingFunction[{{0.,2000.}},<>][x]}},{}}[[2,1]]}
Any kind of help or suggestion will great .Even if you can help using other method like using for loop and logical condition that will be great too.
soln
bits. This will workdata = Table[ Reap[NDSolve[{I D[v[x], x] == (0.4 + a)*v[x], v[0] == 1}, {v[x]}, {x, 0, 2000}, Method -> {"EventLocator", "Event" -> Abs[v[x]]^2, "EventCondition" -> x == 2000, "EventAction" :> Sow[{a, Abs[v[x]]^2}]}]], {a, -1, 0, 0.3}]
You don't get any points becauseAbs[v[x]]
is never zero. $\endgroup$