Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- transformation = Transformation(MultiplyBy(5), Add(10))
- transformed_4 = transformation(4)
- restored_4 = transformation.restore(transformed_4)
- assert restored_4 == 4 # не будем учитывать пока ошибки округления
- from sympy import symbols, solve, simplify, factor
- from sympy.parsing.sympy_parser import (
- parse_expr,
- standard_transformations,
- implicit_multiplication,
- implicit_multiplication_application)
- trf = (
- standard_transformations +
- (implicit_multiplication_application,))
- x, y, z, t = symbols('x y z t')
- formula_str = "5*x + 10"
- formula = parse_expr(formula_str, transformations=trf)
- print(formula)
- #5*x + 10
- res = formula.subs(x, 4)
- print(res)
- #30
- # решение уравнения: `5*x + 10 = 0`
- print(solve(formula))
- #[-2]
- # решение уравнения: `5*x + 10 = 30` или `5*x + 10 - 30 = 0`
- print(solve(formula_str + f" - {res}"))
- #[4]
- In [94]: [r for r in solve('x**4-(x-2)**2') if r.is_real]
- Out[94]: [-2, 1]
- In [95]: simplify('sin(x)**2 + cos(x)**2')
- Out[95]: 1
- In [96]: factor('x**4-(x-2)**2')
- Out[96]: (x - 1)*(x + 2)*(x**2 - x + 2)
- In [100]: simplify('sin(x)**2 / (1 - sin(x)**2)')
- Out[100]: tan(x)**2
- class Transform():
- def __init__(self,x=0,mul=1,add=0):
- self.x = x
- self.mul = mul
- self.add = add
- def calculate (self):
- self.res = self.x*self.mul + self.add
- return self.res
- def reverse (self):
- self.reverse = (self.res-self.add)/self.mul
- return self.reverse
- def expose (self):
- return "{}x{}+{}".format(self.x, self.mul, self.add)
- eq1 = Transform(5, 2, 20)
- print(eq1.calculate())
- print(eq1.expose())
- print(eq1.reverse())
- 30
- 5x2+20
- 5.0
Add Comment
Please, Sign In to add comment