Files
Fangchen Li dfc289289d Drop py2 support (#629)
* remove xrange compat shim
* remove str compat shim
* remove exec compat shim
* remove object from class defination
* remove misc workarounds for python versions <3.5
* remove __future__ imports
* update readme
* Update setup.cfg

Closes #594

Co-authored-by: Fredrik Johansson <fredrik.johansson@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Colin B. Macdonald <cbm@m.fsf.org>
2023-03-30 04:50:18 +03:00

36 lines
885 B
Python

"""
Function plotting demo.
"""
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 range(10):
if i == 0:
s = input('Enter a function: ')
else:
s = 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 = input('Enter xmin, xmax (optional): ')
if xlim:
xlim = eval(xlim)
else:
xlim = [-5, 5]
print("Plotting...")
plot(functions, xlim=xlim)
main()