Files
mathgenerator/mathgenerator/funcs/calculus/stationary_points.py
2021-10-07 00:14:39 -04:00

29 lines
899 B
Python

from .__init__ import *
import sympy
def gen_func(maxExp=3, maxCoef=10, format='string'):
while True:
x = sympy.symbols('x')
problem = 0
for exp in range(maxExp + 1):
coefficient = random.randint(0, maxCoef)
problem += coefficient * pow(x, exp)
solution = sympy.stationary_points(problem, x)
# if len(solution) != 0:
solution = ','.join(
'({},{})'.format(str(p), sympy.sympify(problem.replace(x, p)))
for p in solution)
problem = 'f(x)=' + str(problem).replace('**', '^')
if format == 'string':
return problem, solution
elif format == 'latex':
return "Latex unavailable"
else:
return problem, solution
stationary_points = Generator("Stationary Points", 110, gen_func,
["maxExp=3", "maxCoef=10"])