<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> import time <EOL> from PyDSTool import * <EOL> from PyDSTool . Toolbox . phaseplane import * <EOL> from common_lib import * <EOL> def make_model ( icdict , pardict ) : <EOL> DSargs = args ( ) <EOL> DSargs . name = '<STR_LIT>' <EOL> DSargs . ics = icdict <EOL> DSargs . pars = pardict <EOL> DSargs . tdata = [ <NUM_LIT:0> , <NUM_LIT> ] <EOL> DSargs . algparams = { '<STR_LIT>' : <NUM_LIT> } <EOL> DSargs . varspecs = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> DSargs . auxvars = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> DSargs . fnspecs = { '<STR_LIT:H>' : ( [ '<STR_LIT:p>' ] , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( [ '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( [ '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> } <EOL> stop_ev = Events . makeZeroCrossEvent ( '<STR_LIT>' , - <NUM_LIT:1> , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True } , <EOL> varnames = [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> fnspecs = DSargs . fnspecs , <EOL> parnames = pardict . keys ( ) , <EOL> targetlang = '<STR_LIT>' ) <EOL> DSargs . events = [ stop_ev ] <EOL> return Generator . Vode_ODEsystem ( DSargs ) <EOL> def animate ( traj , tlo = <NUM_LIT:0> , thi = None , dt = <NUM_LIT:0> ) : <EOL> if dt == <NUM_LIT:0> : <EOL> pts = traj . sample ( tlo = tlo , thi = thi ) <EOL> ts = pts [ '<STR_LIT:t>' ] <EOL> else : <EOL> pts = traj . sample ( tlo = tlo , thi = thi , dt = dt , precise = True ) <EOL> ts = pts [ '<STR_LIT:t>' ] <EOL> plt . figure ( <NUM_LIT:0> ) <EOL> plt . clf ( ) <EOL> plt . axis ( [ - <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> ] ) <EOL> ax = plt . gca ( ) <EOL> ax . set_autoscale_on ( False ) <EOL> ax . set_aspect ( '<STR_LIT>' ) <EOL> p = linspace ( <NUM_LIT:0> , <NUM_LIT:2> * pi ) <EOL> plt . plot ( cos ( p ) , sin ( p ) , '<STR_LIT>' ) <EOL> plt . xlim ( [ - <NUM_LIT> , <NUM_LIT> ] ) <EOL> plt . ylim ( [ - <NUM_LIT> , <NUM_LIT> ] ) <EOL> theta1 = plt . plot ( [ <NUM_LIT:0> , <NUM_LIT:0> ] , '<STR_LIT>' , label = '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> theta2 = plt . plot ( [ <NUM_LIT:0> , <NUM_LIT:0> ] , '<STR_LIT>' , label = '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> plt . legend ( ) <EOL> ts = pts [ '<STR_LIT:t>' ] <EOL> for i , pt in enumerate ( pts ) : <EOL> theta1 . set_data ( ( cos ( pt [ '<STR_LIT>' ] ) , sin ( pt [ '<STR_LIT>' ] ) ) ) <EOL> theta2 . set_data ( ( cos ( pt [ '<STR_LIT>' ] ) , sin ( pt [ '<STR_LIT>' ] ) ) ) <EOL> plt . draw ( ) <EOL> def test ( ** kw ) : <EOL> icdict = filteredDict ( kw , DS . funcspec . vars ) <EOL> pardict = filteredDict ( kw , DS . pars . keys ( ) ) <EOL> DS . set ( ics = icdict , pars = pardict ) <EOL> traj = DS . compute ( '<STR_LIT:test>' ) <EOL> pts = traj . sample ( ) <EOL> plt . figure ( <NUM_LIT:1> ) <EOL> plt . clf ( ) <EOL> plt . plot ( pts [ '<STR_LIT:t>' ] , pts [ '<STR_LIT>' ] , '<STR_LIT:r>' , label = '<STR_LIT>' ) <EOL> plt . plot ( pts [ '<STR_LIT:t>' ] , pts [ '<STR_LIT>' ] , '<STR_LIT:k>' , label = '<STR_LIT>' ) <EOL> plt . legend ( ) <EOL> plt . ylim ( [ - <NUM_LIT> , <NUM_LIT> ] ) <EOL> plt . figure ( <NUM_LIT:2> ) <EOL> plt . clf ( ) <EOL> plt . plot ( pts [ '<STR_LIT:t>' ] , pts [ '<STR_LIT>' ] , '<STR_LIT:b>' , linewidth = <NUM_LIT:2> , label = '<STR_LIT>' ) <EOL> plt . show ( ) <EOL> return traj , pts <EOL> def stability ( pts ) : <EOL> """<STR_LIT>""" <EOL> if pts [ '<STR_LIT>' ] [ - <NUM_LIT:1> ] > DS . pars [ '<STR_LIT>' ] : <EOL> print "<STR_LIT>" <EOL> return <EOL> phi = pts [ '<STR_LIT>' ] [ - <NUM_LIT:1> ] <EOL> print "<STR_LIT>" , pts [ '<STR_LIT>' ] [ - <NUM_LIT:1> ] <EOL> a1 = DS . pars [ '<STR_LIT>' ] <EOL> a2 = DS . pars [ '<STR_LIT>' ] <EOL> sigma = DS . pars [ '<STR_LIT>' ] <EOL> cond = - ( a2 - a1 ) * sin ( sigma ) * sin ( phi ) - ( a1 + a2 ) * cos ( sigma ) * cos ( phi ) <EOL> if cond < <NUM_LIT:0> : <EOL> result = '<STR_LIT>' <EOL> else : <EOL> result = '<STR_LIT>' <EOL> print '<STR_LIT>' % cond , result <EOL> icdict = { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT> } <EOL> pardict = { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : - <NUM_LIT> , '<STR_LIT>' : - <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> } <EOL> DS = make_model ( icdict , pardict ) <EOL> traj , pts = test ( p2 = <NUM_LIT:0.> , a1 = - <NUM_LIT> ) <EOL> stability ( pts ) </s>
