from __future__ import annotations from src.main import Derivative import plotly.express as px class ProductRule: def __init__(self, func1_expression, func2_expression, start_stop_num: List[int, int, int] = [-10, 10, 200]): self.func1 = Derivative(expression = func1_expression) self.func2 = Derivative(expression = func2_expression) self.func1() self.func2() self.derivative = self._get_derivative() self.y_values = self._get_y_values() def _get_derivative(self): product_rule = self.func1.y * self.func2.derivative + self.func1.derivative * self.func2.y return product_rule def _get_y_values(self): return self.func1.y * self.func2.y def _plot_f(self): fig = px.scatter(x = self.func1.x, y = self.y_values, title = "Product Function") return fig def _plot_dev(self): fig = px.scatter(x = self.func1.x, y = self.derivative, title = "Derivative") return fig def plot(self): return self._plot_f(), self._plot_dev() def get_pr_fn(input1: str, input2: str): pr_obj = ProductRule(input1, input2) f_fig, _ = pr_obj.plot() return f_fig def get_pr_dev(input1: str, input2: str): pr_obj = ProductRule(input1, input2) _, dev_fig = pr_obj.plot() return dev_fig