def Prob(PVar1, PVar2, PVar3, PVar4, PVar5, PVar6, PVar7, PVarP, answerE, answerV): ExpectedV = ((PVar1 * PVarP) + (PVar2 * PVarP) + (PVar3 * PVarP) + (PVar4 * PVarP) + (PVar5 * PVarP) + (PVar6 * PVarP) + (PVar7 * PVarP)) ExpectedVsq = (((PVar1)**2 * PVarP) + ((PVar2)**2 * PVarP) + ((PVar3)**2 * PVarP) + ((PVar4)**2 * PVarP) + ((PVar5)**2 * PVarP) + ((PVar6)**2 * PVarP) + ((PVar7)**2 * PVarP)) #This is the equation for working out the Variance. Var(x) = E(x**2) - (E(x)**2) VarianceV = ExpectedVsq - (ExpectedV**2) return True if (f_equals(answerE, ExpectedV)) and (f_equals(answerV, VarianceV)) else False
def mark(self): """ This function deterimines if the input gets a mark or not """ attempt = self.parser.parse() function = equationMaker(self.qvariables) return True if (f_equals(attempt, sympy.integrate(function, x))) else False
def VectorDot(VectorA, VectorB, answer): VectorA = convert_Vector(VectorA) VectorB = convert_Vector(VectorB) Dotproduct = (VectorA0 * VectorB0) + (VectorA1 * VectorB1) + (VectorA2 * VectorB2) return True if (f_equals(answer, Matrix.T)) else False
def mark(self): """Takes the first variable which is x coordinate of point and the rest makes equation""" attempt = self.parser.parse() point = (self.qvariables[:1])[0] function = equationMaker(self.qvariables[1:]) return True if (f_equals(attempt, sympy.diff(function, x).subs(x, point))) else False
def Remainder(function, functionvalue, answer): #Need someone just to double check this, but you will need the value of f(x) = "to something" seperate than the function function = convert_equation(function) functionvalue = convert_equation(functionvalue) answer = convert_equation(answer) remainderf = solve(Eq(function, x).subs(x, functionvalue)) return True if (f_equals(answer, remainderf)) else False
def mark(self): """ This solves for the product rule, takes the values 'u' and 'v' and differentiate them """ attempt = self.parser.parse() u = equationMaker(self.qvariables[0]) v = equationMaker(self.qvariables[1]) function = "(" + str(u) + ")*(" + str(v) + ")" return True if f_equals(attempt, sympy.diff(function, x)) else False
def mark(self): """ This solves the quoitent rule, by differeniating u over v """ attempt = self.parser.parse() u = equationMaker(self.qvariables[0]) v = equationMaker(self.qvariables[1]) function = "(" + str(u) + ")/(" + str(v) + ")" return True if f_equals(attempt, sympy.diff(function, x)) else False
def MatrixMultiply(MatrixM, MatrixN, answer): MatrixM = convert_Matrix(MatrixM) MatrixN = convert_Matrix(MatrixN) answer = convert_Matrix(answer) Multi = MatrixM * MatrixN return True if (f_equals(answer, Multi)) else False
def VectorCross(VectorA, VectorB, answer): VectorA = convert_Vector(VectorA) VectorB = convert_Vector(VectorB) Crossproducti = (VectorA1 * VectorB2) - (VectorA2 * VectorB1) Crossproductj = (VectorA0 * VectorB2) - (VectorA2 * VectorB0) Crossproductk = (VectorA0 * VectorB1) - (VectorA1 * VectorB0) Cross = (Crossproducti * i) - (Crossproductj * j) + (Crossproductk * k) return True if (f_equals(answer, Cross)) else False
def find_equation_of_normal(function, point, answer): x0 = point[0] y0 = point[1] function = convert_equation(function) answer = convert_equation(answer) n = - (1 / (sympy.diff(function, x).subs(x, x0))) normal = n*x + y0 - n*x0 return True if f_equals(answer, normal) else False
def find_equation_of_tangent(function, point, answer): x0 = point[0] y0 = point[1] function = convert_equation(function) answer = convert_equation(answer) m = sympy.diff(function, x).subs(x, x0) tangent = m*x + y0 - m*x0 return True if f_equals(answer, tangent) else False
def MatrixCofactor(Matrix, answer): Matrix = convert_Matrix(Matrix) def cofactorMatrix(Matrix, method="berkowitz"): #Return a matrix containing the cofactor of each element. out = Matrix._new(Matrix.rows, Matrix.cols, lambda i,j: Matrix.cofactor(i, j, method)) return out answer = convert_Matrix(answer) return True if (f_equals(answer, cofactorMatrix(Matrix))) else False
def Choose(VarO, Var1, Var2, Var3, answer): answer = convert_equation(answer) #This creates a needed value that is the opposite to the required variable Ne = VarO - Var3 #This creates the value that allows the maximum number of chooses and still gets the required number of objects Bc = Ne - Var2 #The creates the value that allows the total maximum number of chooses before the goal cannot be reached Be = VarO - Var2 #This is the total number of combinations that could be made to take out the required numbers irregradless of what is taken out Ch1 = (math.factorial(VarO)) / (math.factorial(Ne) * math.factorial(VarO - Ne)) #This is the total number of combinations that could be made to take out the required number with notice to what is taken out Ch2 = (math.factorial(Be)) / (math.factorial(Bc) * math.factorial(Be - Bc)) #This determines the actuall probability of the question ans = Ch2 / Ch1 return True if (f_equals(answer, ans)) else False
def MatrixTranspose(Matrix, answer): Matrix = convert_Matrix(Matrix) answer = convert_Matrix(answer) return True if (f_equals(answer, Matrix.T)) else False
def Factorisation(function, answer): function = convert_equation(function) answer = convert_equation(answer) return True if (f_equals(answer, sympy.factor(function))) else False
def Simplification(function, answer): function = convert_equation(function) answer = convert_equation(answer) return True if (f_equals(answer, sympy.simplify(function))) else False
def Intergrate_this(function, answer): function = convert_equation(function) answer = convert_equation(answer) return True if (f_equals(answer, sympy.integrate(function, x))) else False
def find_gradient_at(function, point, answer): function = convert_equation(function) return True if (f_equals(answer, sympy.diff(function, x).subs(x, point))) else False
def differentiate_this(function, answer): function = convert_equation(function) answer = convert_equation(answer) return True if (f_equals(answer, sympy.diff(function, x))) else False
def MatrixInverse(Matrix, answer): Matrix = convert_Matrix(Matrix) answer = convert_Matrix(answer) return True if (f_equals(answer, sympy.Matrix.inv("LU"))) else False
def MatrixDet(Matrix, answer): Matrix = convert_Matrix(Matrix) answer = convert_Matrix(answer) return True if (f_equals(answer, sympy.Matrix.det())) else False