Add Stationary Points

This commit is contained in:
Allen Guan
2020-10-26 05:19:32 +08:00
parent 5ffa50b1f3
commit b505b6ba52
3 changed files with 23 additions and 0 deletions

View File

@@ -111,3 +111,4 @@ from .decimal_to_bcd import *
from .circumference import *
from .combine_like_terms import *
from .conditional_probability import *
from .stationary_points import *

View File

@@ -0,0 +1,21 @@
from .__init__ import *
import sympy
def stationaryPointsFunc(maxExp=3, maxCoef=10):
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('**', '^')
return problem, solution
stationary_points = Generator("Stationary Points", 106, "f(x)=x^3-3x", "(-1,2),(1,-2)", stationaryPointsFunc)