#
# pendulum.py
#
# Python file for the vector field named: pendulum
# The functions defined here can be used with the ODEIV routines of PyGSL.
#
# This file was generated by the program VFGEN (Version:2.4.0)
# Generated on 10-Jul-2008 at 17:45
#

from math import *
import Numeric

#
# The vector field.
#

def vectorfield(t,x_,args):
    """
    The vector field function for the vector field "pendulum"
    """
    Pi = Numeric.pi
    theta      = x_[0]
    v          = x_[1]
    g          = args[0]
    b          = args[1]
    L          = args[2]
    m          = args[3]

    f_ = Numeric.zeros((2,),Numeric.Float)
    f_[0] = v
    f_[1] = -1.0/m*v/(L*L)*b-sin(theta)*g/L

    return f_

#
#  The Jacobian.
#

def jacobian(t_, y_, args):
    """
    The Jacobian of the vector field "pendulum"
    """
    Pi = Numeric.pi
    theta      = y_[0]
    v          = y_[1]
    g          = args[0]
    b          = args[1]
    L          = args[2]
    m          = args[3]

    # Create the Jacobian matrix, initialized with zeros.
    jac_ = Numeric.zeros((2,2),Numeric.Float)
    jac_[0,1] = 1.0
    jac_[1,0] = -g/L*cos(theta)
    jac_[1,1] = -1.0/m/(L*L)*b

    dfdt_ = Numeric.zeros((2,),Numeric.Float)

    return jac_,dfdt_

#
# User function: energy
#

def energy(t_, y_, args):
    """
    The user-defined function "energy" for the vector field "pendulum"
    """
    Pi = Numeric.pi
    theta      = y_[0]
    v          = y_[1]
    g          = args[0]
    b          = args[1]
    L          = args[2]
    m          = args[3]

    return -m*g*L*cos(theta)+m*(v*v)*(L*L)/2.0

