# Problem with Eventlocator Method for NDSolve

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 == 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.

• I think you don't need the soln bits. This will work data = Table[ Reap[NDSolve[{I D[v[x], x] == (0.4 + a)*v[x], v == 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 because Abs[v[x]] is never zero. Jul 19 '12 at 10:48
• I tried that but did not work. Thanks.
– Mush
Jul 19 '12 at 11:52
• Could you specify what does not work ? Jul 19 '12 at 13:37

Maybe you can do it more simply :

xvalue = 1000;
avalues = Range[-1, 0, 0.3];
results = Table[NDSolve[{I D[v[x], x] == (0.4 + a)*v[x], v == 1},
v[x], {x, 0, 2000}][[1, 1, 2]] /. x -> xvalue, {a, avalues}]

(* {-0.999044 + 0.0441925 I, -0.0221014 - 0.999765 I, 1. + 0. I, -0.0221014 + 0.999765 I} *) • Its working! Thanks a lot! :)
– Mush
Jul 19 '12 at 11:53
• Do you have a BRG ordered screen? Jul 19 '12 at 13:43
• @Szabolcs I'm sorry but I don't know what it is. Jul 19 '12 at 13:59
• @Mush More generally than row/column, which applies to 2 dimensional lists, [[...]] (shorthand for Part) applies to lists of any dimensions. In my case [[1,1,2]] extracts the InterpolationFunction solution to the equation so I can calculate its value at the point of interest. Jul 19 '12 at 19:54
• @Mush The solution is in the the form example = {{v[x] -> InterpolationFunction[...]}}; example[] = {v[x] -> InterpolationFunction[...]}; example[[1,1]] = v[x] -> InterpolationFunction[...]; example[[1,1,2]] = InterpolationFunction[...]; Jul 19 '12 at 20:44