Skip to content

Instantly share code, notes, and snippets.

@metula
Last active January 1, 2016 14:49
Show Gist options
  • Save metula/8160018 to your computer and use it in GitHub Desktop.
Save metula/8160018 to your computer and use it in GitHub Desktop.
def square(x):
return x**2
def linear(x):
return 2 * x + 1
def pow10(x):
return x**10
def integral(f, h=0.001):
""" definite integral: function of a, b """
return lambda a, b: h * sum(f(a + i * h) for i in range(0, int((b - a) / h)))
def integral_mid(f, h=0.001):
""" definite integral: function of a, b
considering f's value in the middle of each interval"""
return lambda a, b: h * sum(f(a + (i + 0.5) * h) for i in range(0, int((b - a) / h)))
# Derivative.
def diff(f, h=0.001):
# when h not specified, default value h=0.001 is used
return lambda x: (f(x + h) - f(x)) / h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment