Ticket #3935: ode_solver_patch.patch

File ode_solver_patch.patch, 2.2 kB (added by jwmerrill, 5 months ago)

Adds a doctest and fixes the init method

  • a/sage/gsl/ode.pyx

    old new  
    242242         sage: f = T.interpolate_solution(i=2) 
    243243         sage: plot(f,0,12).show() 
    244244         sage: f = T.interpolate_solution() 
    245          sage: f(pi)                # slightly random precision 
    246          0.53794722843358245 
     245         sage: f(pi) 
     246         0.5379... 
     247 
     248         The solver attributes may also be set up using arguments to ode_solver.  The previous example can be rewritten as 
     249 
     250         sage: T = ode_solver(g_1,y_0=[0,1,1],scale_abs=[1e-4,1e-4,1e-5],error_rel=1e-4) 
     251         sage: T.ode_solve(t_span=[0,12],num_points=100) 
     252         sage: f = T.interpolate_solution() 
     253         sage: f(pi) 
     254         0.5379...         
    247255 
    248256         Unfortunately because python functions are used, this solver is slow on system that require many function evaluations. 
    249257         It is possible to pass a compiled function by deriving from the class ode_sysem and overloading c_f and c_j with C functions that 
     
    284292   def __init__(self,function=None,jacobian=None,h = 1e-2,error_abs=1e-10,error_rel=1e-10, a=False,a_dydt=False,scale_abs=False,algorithm="rkf45",y_0=None,t_span=None,params = []): 
    285293      self.function = function 
    286294      self.jacobian = jacobian 
    287       self.h=1e-2 
     295      self.h = h 
    288296      self.error_abs = error_abs 
    289       self.error_rel = error_abs 
    290       self.a = False 
    291       self.a_dydt = False 
    292       self.scale_abs=False 
    293       self.algorithm = "rkf45" 
    294       self.y_0=None 
    295       self.t_span = None 
    296       self.params = [] 
    297       self.solution=[] 
     297      self.error_rel = error_rel 
     298      self.a = a 
     299      self.a_dydt = a_dydt 
     300      self.scale_abs = scale_abs 
     301      self.algorithm = algorithm 
     302      self.y_0 = y_0 
     303      self.t_span = t_span 
     304      self.params = params 
     305      self.solution = [] 
    298306 
    299307   def __setattr__(self,name,value): 
    300308      if(hasattr(self,'solution')):