mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 14:35:23 +01:00
29 lines
899 B
Python
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"])
|