#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 25 13:00:45 2018

@author: troll
"""

class FuncWithDerivatives():
    def __init__(self, h=1.0E-5):
        self.h = h 

    def __call__(self, x):
        raise NotImplementedError\
        ('___call__ missing in class %s' % self.__class__.__name__)

    def df(self, x):
        # Liefert Approximation an 1. Ableitung
        # Compute first derivative by a finite difference
        h = self.h
        return (self(x+h) - self(x-h))/(2.0*h)
    
    def ddf(self, x):
        # Return the 2nd derivative of self.f.
        # Compute second derivative by a finite difference:
        h = self.h
        return (self(x+h) - 2*self(x) + self(x-h))/(float(h)**2)