From 22da9215548b5e9914d70c425467e6ddeec8510b Mon Sep 17 00:00:00 2001 From: Morax Date: Tue, 29 Oct 2024 21:16:57 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E8=BF=87=E6=AD=A3=E5=88=99=E8=A1=A8?= =?UTF-8?q?=E8=BE=BE=E5=BC=8F=E6=94=AF=E6=8C=81=E4=BA=86sin^-1(x),=20tan^-?= =?UTF-8?q?1(x),=20cos^-1(x)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/main.py b/main.py index 2995467..aac882b 100644 --- a/main.py +++ b/main.py @@ -180,6 +180,19 @@ def repl(match): expr_str = re.sub(r'\|([^|]+)\|', repl, expr_str) return expr_str + def replace_inverse_trig_functions(self, expr_str): + def repl(match): + func = match.group(1) + arg = match.group(2) + return f'a{func}({arg})' + patterns = [ + r'(sin|cos|tan)\^-1\s*(\([^)]*\)|\w+)', + r'(sin|cos|tan)⁻¹\s*(\([^)]*\)|\w+)' + ] + for pattern in patterns: + expr_str = re.sub(pattern, repl, expr_str) + return expr_str + def plot_graphs_2d(self): self.result_browser.clear() equations_input = self.entry_2d.text() @@ -203,6 +216,7 @@ def plot_graphs_2d(self): local_dict = { 'x': x, 'e': np.e, 'pi': np.pi, 'sin': sp.sin, 'cos': sp.cos, 'tan': sp.tan, + 'asin': sp.asin, 'acos': sp.acos, 'atan': sp.atan, 'log': sp.log, 'sqrt': sp.sqrt, 'Abs': sp.Abs, 'exp': sp.exp, 'ln': sp.log, 'sinh': sp.sinh, 'cosh': sp.cosh, 'tanh': sp.tanh, @@ -219,6 +233,7 @@ def plot_graphs_2d(self): self.lines = [] self.modules = { 'sin': np.sin, 'cos': np.cos, 'tan': np.tan, + 'asin': np.arcsin, 'acos': np.arccos, 'atan': np.arctan, 'log': np.log, 'sqrt': np.sqrt, 'Abs': np.abs, 'exp': np.exp, 'ln': np.log, 'e': np.e, 'pi': np.pi, 'sinh': np.sinh, 'cosh': np.cosh, 'tanh': np.tanh, @@ -234,6 +249,7 @@ def plot_graphs_2d(self): for idx, equation in enumerate(equations): try: equation = self.replace_absolute_value(equation) + equation = self.replace_inverse_trig_functions(equation) expr = parse_expr( equation, transformations=transformations, local_dict=local_dict) symbols_in_expr = expr.free_symbols