Using StoppingTest in NDSolve

*To*: mathgroup at smc.vnet.net*Subject*: [mg49533] Using StoppingTest in NDSolve*From*: Urijah Kaplan <uak at sas.upenn.edu>*Date*: Fri, 23 Jul 2004 05:59:21 -0400 (EDT)*Organization*: University of Pennsylvania*Sender*: owner-wri-mathgroup at wolfram.com

Hello, I don't know if what I want to do is possible...briefly, I have a numerical diff. equation of a chaotic pendulum, that is I trace the path of a pendulum over three magnets and the pendulum eventually stops over one of them. In order to save (computational) time, I would like NDsolve to stop when it's clear that the pendulum is going to stay over one of the magnets. I also want it to progress for a minimum of time, say t (the independent variable) going to 100. Here is a what I tried for a similar example NDSolve[{f''[x] + f[x] == 0, f[0] == 0, f'[0] == 1}, f, { x, 0, 10}, StoppingTest -> (Which[x < 5, False, Abs[f[x] - f[x - 1]] < .1, True])] here if x is less than 5 I want to continue; and if 5<x<10, and if the absolute difference between f[x] and f[x-1] is less than a small amount (say .1) NDSolve will stop. I'm pretty sure the problem here is that Mtm doesn't know what to do with f[x-1]. Does anyone have any suggestions? Also, if someone can figure out how to do this, how would I save the stopping value to a variable? Say NDSolve stopped at t=20.2, (i.e. the InterpolatingFunction stops at 20.2) how do I save that number. Thank you very much for any help. --Urijah Kaplan If it helps, here is the actual problem R = 0.15; x1 = Sqrt[3] - 1; x2 = -Sqrt[3] - 1; x3 = 0 - 1; y1 = 1; y2 = 1; y3 = -2; c = 0.2; d = 0.25; magnetx1 = Derivative[2][x][t] + R*Derivative[1][x][t] - (x1 - x[t])/ Sqrt[(x1 - x[t])^2 + (y1 - y[t])^2 + d^2]^3 - (x2 - x[t])/Sqrt[(x2 - x[t])^2 + (y2 - y[t])^2 + d^2]^3 - (x3 - x[t])/ Sqrt[(x3 - x[t])^2 + (y3 - y[t])^2 + d^2]^3 + c*x[t] == 0; magnety1 = Derivative[2][y][t] + R*Derivative[1][y][t] - (y1 - y[t])/Sqrt[(x1 - x[t])^2 + (y1 - y[t])^2 + d^2]^3 - (y2 - y[t])/ Sqrt[(x2 - x[t])^2 + (y2 - y[t])^2 + d^2]^3 - (y3 - y[t])/Sqrt[(x3 - x[t])^2 + (y3 - y[t])^2 + d^2]^3 + c*y[t] == 0; solution = NDSolve[{magnetx1, magnety1, x[0] == 2.5, Derivative[1][x][0] == 0, y[0] == 2.5, Derivative[1][y][0] == 0}, {x, y}, {t, 0, 100}, MaxSteps -> 10000]; xy[t_] = {x[t], y[t]} /. solution; Plot[Evaluate[{x[t], y[t]} /. solution], {t, 0, 50}, PlotRange -> All]

**Follow-Ups**:**Re: Using StoppingTest in NDSolve***From:*Ramesh Raju Mudunuri <rmudunuri@uh.edu>