File size: 1,383 Bytes
79402cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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