1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
"""
Function plotting demo.
"""
from __future__ import print_function
from mpmath import *
def main():
print("""
Simple function plotting. You can enter one or several
formulas, in ordinary Python syntax and using the mpmath
function library. The variable is 'x'. So for example
the input "sin(x/2)" (without quotation marks) defines
a valid function.
""")
functions = []
for i in xrange(10):
if i == 0:
s = raw_input('Enter a function: ')
else:
s = raw_input('Enter another function (optional): ')
if not s:
print()
break
f = eval("lambda x: " + s)
functions.append(f)
print("Added f(x) = " + s)
print()
xlim = raw_input('Enter xmin, xmax (optional): ')
if xlim:
xlim = eval(xlim)
else:
xlim = [-5, 5]
print("Plotting...")
plot(functions, xlim=xlim)
main()
|