How do I create the function and the first and second derivatives. I've included the code that has multiple bugs in it. Can anyone help? I'm new to python

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()

Can you repost your code formatted?
To format your code you need to

  1. select it after posting it here and press ctrl +k or </> in the tools pane
  2. Or put three reverse quotes at the beginning of the code and the same thing at the end of it
# 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()