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__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
x, y, z, t, X, Y, Z, T = symbols('x y z t X Y Z T')
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def hello():
|
def hello():
|
||||||
return render_template('index.html')
|
return render_template('index.html')
|
||||||
|
|
@ -15,14 +17,8 @@ def differentiation():
|
||||||
if not request.form.get("function"):
|
if not request.form.get("function"):
|
||||||
return apology("must provide a function", 400)
|
return apology("must provide a function", 400)
|
||||||
f = request.form.get("function")
|
f = request.form.get("function")
|
||||||
"""
|
|
||||||
TODO:
|
f = setup_symbols(f)
|
||||||
take Function
|
|
||||||
analyse to find most common letter (our variable)
|
|
||||||
set that as the basis for symbols
|
|
||||||
"""
|
|
||||||
x = symbols('x')
|
|
||||||
f = sympify(f)
|
|
||||||
|
|
||||||
# Differentiate and return latex expressions
|
# Differentiate and return latex expressions
|
||||||
fprime = latex(f.diff(x))
|
fprime = latex(f.diff(x))
|
||||||
|
|
@ -199,6 +195,13 @@ def errorhandler(e):
|
||||||
e = InternalServerError()
|
e = InternalServerError()
|
||||||
return apology(e.name, e.code)
|
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__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import requests
|
||||||
|
|
||||||
from flask import redirect, render_template, request, session
|
from flask import redirect, render_template, request, session
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
from sympy import *
|
||||||
|
|
||||||
|
|
||||||
def apology(message, code=400):
|
def apology(message, code=400):
|
||||||
|
|
@ -36,3 +37,10 @@ def login_required(f):
|
||||||
def usd(value):
|
def usd(value):
|
||||||
"""Format value as USD."""
|
"""Format value as USD."""
|
||||||
return f"${value:,.2f}"
|
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