From b505b6ba525c1b086138bf7794561f3e089416f0 Mon Sep 17 00:00:00 2001 From: Allen Guan Date: Mon, 26 Oct 2020 05:19:32 +0800 Subject: [PATCH] Add Stationary Points --- README.md | 1 + mathgenerator/funcs/__init__.py | 1 + mathgenerator/funcs/stationary_points.py | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 mathgenerator/funcs/stationary_points.py diff --git a/README.md b/README.md index 4ed2096..84ae8b0 100644 --- a/README.md +++ b/README.md @@ -138,3 +138,4 @@ problem, solution = mathgen.genById(0) | 104 | Circumference | Circumference of circle with radius 60 | 376.99111843077515 | circumference | | 105 | Combine Like terms | 4x^4 + 6x^4 + 9x^1 + 3x^1 + 5x^4 + 10x^3 | 12x^1 + 10x^3 + 15x^4 | combine_like_terms | | 105 | Conditional Probability | Someone tested positive for a nasty disease which only 1.34% of population have. Test sensitivity (true positive) is equal to SN= 98.05% whereas test specificity (true negative) SP= 92.32%. What is the probability that this guy really has that disease? | 14.78% | conditional_probability | +| 106 | Stationary Points | f(x)=x^3-3x | (-1,2),(1,-2) | stationary_points | diff --git a/mathgenerator/funcs/__init__.py b/mathgenerator/funcs/__init__.py index 575dcd2..ad9edd0 100644 --- a/mathgenerator/funcs/__init__.py +++ b/mathgenerator/funcs/__init__.py @@ -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 * diff --git a/mathgenerator/funcs/stationary_points.py b/mathgenerator/funcs/stationary_points.py new file mode 100644 index 0000000..93ff673 --- /dev/null +++ b/mathgenerator/funcs/stationary_points.py @@ -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)