# objectives: 1) demonstrate numerical differentialtion,

# and 2) illustrate results graphically.

import numpy

import math

from numpy import arange, cos

import matplotlib.pyplot

from matplotlib.pyplot import *

# A general function for calculating the slope between two points: x and

# x+delta.

def der(x,delta):

delta = float(delta)

if delta < (0.0000001):

print (‘Value chosen for delta is too small.’)

return 1/delta

else:

slope = (f(x + delta) - f(x))/delta

return slope

# Define the function y=100e^(-0.0482t)

def f(x):

f = (100.0**(-0.0482*x))

return f

point = 2.0 #This is a point at which a derivative will be calculated.

# The following statements initialize variables for computation.

number = 510

increment =10

y =

x =

figure()

f=[3,-4,-12,0,2]

print (’\nFunction’)

print f

print (’\nFirst Derivative’)

g= f.deriv(m=1) # First derivative with m=1.

print g

print (’\nSecond Derivative’)

q= f.deriv(m=2) # Second derivative with m=2.

print q

x=linspace(-2,3,101)

y=p(x)

yg=g(x) # These statements define points for plotting.

yq=q(x)

y0=0*x # This statement defines the y axis for plotting.

plot (x,y,label =‘y=f(x)’)

plot (x,yg,label =‘First Derivative’)

plot (x,yq,label =‘Second Derivative’)

legend(loc=‘best’)

plot (x,y0)

xlabel(‘x-axis’)

ylabel(‘y-axis’)

title (‘Plot Showing Function, First and Second Derivatives’)

show()