From e01f17c0a62c311d54f2e3123aeeeb5ca162897f Mon Sep 17 00:00:00 2001 From: Akash Saravanan Date: Thu, 15 Oct 2020 00:50:08 +0530 Subject: [PATCH] Add power rule differentiation. --- mathgenerator/mathgen.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 0931109..911f979 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -78,6 +78,20 @@ def squareRootFunction(minNo = 1, maxNo = 12): solution = str(b) return problem, solution +def powerRuleDifferentiationFunc(maxCoef = 10, maxExp = 10, maxTerms = 5): + numTerms = random.randint(1, maxTerms) + problem = "" + solution = "" + for i in range(numTerms): + if i > 0: + problem += " + " + solution += " + " + coefficient = random.randint(1, maxCoef) + exponent = random.randint(1, maxExp) + problem += str(coefficient) + "x^" + str(exponent) + solution += str(coefficient * exponent) + "x^" + str(exponent - 1) + return problem, solution + # || Class Instances #Format is: @@ -88,4 +102,5 @@ multiplication = Generator("Multiplication", 4, "a*b=", "c", multiplicationFunc) division = Generator("Division", 5, "a/b=", "c", divisionFunc) binaryComplement1s = Generator("binary_complement_1s", 6, "1010=", "0101", binaryComplement1sFunc) moduloDivision = Generator("Modulo_Division", 7, "a%b=", "c", moduloFunc) -squareRoot = Generator("Square _Root", 8, "sqrt(a)=", "b", squareRootFunction) \ No newline at end of file +squareRoot = Generator("Square _Root", 8, "sqrt(a)=", "b", squareRootFunction) +powerRuleDifferentiation = Generator("Power_Rule_Differentiation", 9, "nx^m=", "(n*m)x^(m-1)", powerRuleDifferentiationFunc) \ No newline at end of file