create and implement the setup_symbols function, symbols are preset at start
This commit is contained in:
parent
44c3a31c92
commit
45a816c46c
Binary file not shown.
19
app.py
19
app.py
|
|
@ -4,6 +4,8 @@ from helpers import apology
|
|||
|
||||
app = Flask(__name__)
|
||||
|
||||
x, y, z, t, X, Y, Z, T = symbols('x y z t X Y Z T')
|
||||
|
||||
@app.route('/')
|
||||
def hello():
|
||||
return render_template('index.html')
|
||||
|
|
@ -15,14 +17,8 @@ def differentiation():
|
|||
if not request.form.get("function"):
|
||||
return apology("must provide a function", 400)
|
||||
f = request.form.get("function")
|
||||
"""
|
||||
TODO:
|
||||
take Function
|
||||
analyse to find most common letter (our variable)
|
||||
set that as the basis for symbols
|
||||
"""
|
||||
x = symbols('x')
|
||||
f = sympify(f)
|
||||
|
||||
f = setup_symbols(f)
|
||||
|
||||
# Differentiate and return latex expressions
|
||||
fprime = latex(f.diff(x))
|
||||
|
|
@ -199,6 +195,13 @@ def errorhandler(e):
|
|||
e = InternalServerError()
|
||||
return apology(e.name, e.code)
|
||||
|
||||
def setup_symbols(f):
|
||||
f = sympify(f)
|
||||
for letter in [x, y, z, t, X, Y, Z, T]:
|
||||
f = f.subs(letter, x)
|
||||
|
||||
return f
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import requests
|
|||
|
||||
from flask import redirect, render_template, request, session
|
||||
from functools import wraps
|
||||
from sympy import *
|
||||
|
||||
|
||||
def apology(message, code=400):
|
||||
|
|
@ -36,3 +37,10 @@ def login_required(f):
|
|||
def usd(value):
|
||||
"""Format value as USD."""
|
||||
return f"${value:,.2f}"
|
||||
|
||||
def setup_symbols(f):
|
||||
f = sympify(f)
|
||||
for letter in [x, y, z, t, X, Y, Z, T]:
|
||||
f = f.subs(letter, x)
|
||||
|
||||
return f
|
||||
|
|
|
|||
Loading…
Reference in New Issue