-
Notifications
You must be signed in to change notification settings - Fork 0
/
Equation.py
36 lines (24 loc) · 963 Bytes
/
Equation.py
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
from typing import Callable
import matplotlib.pyplot as plt
import numpy as np
from scipy.misc import derivative
dx = 0.00001
class Equation:
def __init__(self, function: Callable, text: str):
self.text = text
self.function = function
def draw(self, left: float, right: float):
x = np.linspace(left, right)
func = np.vectorize(self.function)(x)
plt.title = 'График заданной функции'
plt.grid(True, which='both')
plt.xlabel('X')
plt.ylabel('Y')
plt.axhline(y=0, color='gray', label='y = 0')
plt.plot(x, func, 'green', label=self.text)
plt.legend(loc='upper left')
plt.savefig('graph.png')
plt.show()
def root_exists(self, left: float, right: float):
return (self.function(left) * self.function(right) < 0) \
and (derivative(self.function, left, dx) * derivative(self.function, left, dx) > 0)