def run_example(with_plots=True):
    r"""
    Example for the use of LSODAR method to solve
    Van der Pol's equation
    
    .. math::
       
        \dot y_1 &= y_2 \\
        \dot y_2 &= \mu ((1.-y_1^2) y_2-y_1)

    with :math:`\mu=\frac{1}{5} 10^3`.

    on return:
    
       - :dfn:`exp_mod`    problem instance
    
       - :dfn:`exp_sim`    solver instance

    """
    
    #Define the rhs
    def f(t,y):
        eps = 1.e-6
        my = 1./eps
        yd_0 = y[1]
        yd_1 = my*((1.-y[0]**2)*y[1]-y[0])
        
        return N.array([yd_0,yd_1])
    
    y0 = [2.0,-0.6] #Initial conditions
    
    #Define an Assimulo problem
    exp_mod = Explicit_Problem(f,y0, name = "LSODAR: Van der Pol's equation")
    
    #Define an explicit solver
    exp_sim = LSODAR(exp_mod) #Create a Radau5 solver
    
    #Sets the parameters
    exp_sim.atol = 1e-4 #Default 1e-6
    exp_sim.rtol = 1e-4 #Default 1e-6
        
    #Simulate
    t, y = exp_sim.simulate(2.) #Simulate 2 seconds
    
     #Plot
    if with_plots:
        import pylab as P
        P.plot(t,y[:,0], marker='o')
        P.title(exp_mod.name)
        P.ylabel("State: $y_1$")
        P.xlabel("Time")
        P.show()
    
    #Basic test
    x1 = y[:,0]
    assert N.abs(x1[-1]-1.706168035) < 1e-3 #For test purpose
    
    return exp_mod, exp_sim
def run_example(with_plots=True):
    """
    Bouncing ball example to demonstrate LSODAR's 
    discontinuity handling.

    Also a way to use :program:`problem.initialize` and :program:`problem.handle_result`
    in order to provide extra information is demonstrated.

    The governing differential equation is

    .. math::

       \\dot y_1 &= y_2\\\\
       \\dot y_2 &= -9.81

    and the switching functions are

    .. math::

       \\mathrm{event}_0 &= y_1 \\;\\;\\;\\text{ if } \\;\\;\\;\\mathrm{sw}_0 = 1\\\\
       \\mathrm{event}_1 &= y_2 \\;\\;\\;\\text{ if }\\;\\;\\; \\mathrm{sw}_1 = 1

    otherwise the events are deactivated by setting the respective value to something different from 0.


    The event handling sets 

    :math:`y_1 = - 0.88 y_1` and :math:`\\mathrm{sw}_1 = 1` if the first event triggers 
    and :math:`\\mathrm{sw}_1 = 0`   if the second event triggers.

    """
    #Create an instance of the problem
    exp_mod = Extended_Problem()  #Create the problem

    exp_sim = LSODAR(exp_mod)  #Create the solver
    exp_sim.atol = 1.e-8
    exp_sim.report_continuously = True

    exp_sim.verbosity = 30

    #Simulate
    t, y = exp_sim.simulate(10.0)  #Simulate 10 seconds

    #Plot
    if with_plots:
        P.subplot(221)
        P.plot(t, y)
        P.title('LSODAR Bouncing ball (one step mode)')
        P.ylabel('States: $y$ and $\dot y$')
        P.subplot(223)
        P.plot(exp_sim.t_sol, exp_sim.h_sol)
        P.title('LSODAR step size plot')
        P.xlabel('Time')
        P.ylabel('Sepsize')
        P.subplot(224)
        P.plot(exp_sim.t_sol, exp_sim.nq_sol)
        P.title('LSODAR order plot')
        P.xlabel('Time')
        P.ylabel('Order')
        P.suptitle(exp_mod.name)
        P.show()
    return exp_mod, exp_sim