# L-33 MCS 507 Mon 7 Nov 2011 : funquaddiff2.py

# For a quadratic function we only define the function,
# and we rely on all other methods of the superclass FunWithDiff.

from funwithdiff import *

class FunQuadDiff(FunWithDiff):
   """
   Overrides the _call__ method
   for a quadratic function.
   """
   def __init__(self,a,b,c,h=1.0e-5):
      """
      Defines a*x^2 + b*x + c.
      """
      self.a = a
      self.b = b
      self.c = c
      self.h = h

   def __call__(self,x):
      """
      Returns a*x^2 + b*x + c.
      """
      a = self.a
      b = self.b
      c = self.c
      return a*x**2 + b*x + c

def main():
   """
   Shows use of FunQuadDiff 
   for 7*x^2 - 5*x + 3. 
   """
   print 'q(x) = 7*x^2 - 5*x + 3'
   q = FunQuadDiff(7,-5,3)
   print 'q(1) =', q(1)
   print 'diff q(1) =', q.df(1)
   print 'diff^2 q(1) =', q.ddf(1)

if __name__=="__main__": main()
