Skip to content

Instantly share code, notes, and snippets.

@emwdx
Created September 5, 2012 09:47
Show Gist options
  • Save emwdx/3634247 to your computer and use it in GitHub Desktop.
Save emwdx/3634247 to your computer and use it in GitHub Desktop.
Table of values generator for evaluating limits
#This program will generate a table of values to help in identifying the left and right hand limits of a function at a value.
#The user can change the values of a (line 10) and the function (line 21) to investigate limits of different functions and different values.
#Entering functions must be done using correct Python syntax. For example, x-squared should be written as x**2.
#Trigonometric, exponential, and other specialized functions can be accessed by typing "math." and then the function.
import math
a = -2 #This is the value that x is approaching in the limit. CHANGE THIS LINE!
dx = 0.5 #This is the initial delta_x to use in approaching the a-value.
x = a - dx #Set the initial value of x to be dx away from a.
#_______________________________________
def f(x):
f = (math.sin(x))/x #This is f(x), the function that is being used for the limit. CHANGE THIS LINE!
return f
#________________________________________
for i in range(10): #Print the function values approaching a from the left.
x = a - dx
print "x: %0.6f f(x): %f" % (x, f(x))
dx = dx*0.5
x = a
print "x: %0.6f f(x): " % (x) #Print the value of a with no function value (in case it is undefined)
#________________________________________
for i in range(10): #Print the function values moving to the right, away from a.
x = a + dx
print "x: %0.6f f(x): %f" % (x, f(x))
dx = dx*2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment