示例#1
0
    def plot(self, line: Polynomial, complexity: str) -> None:
        fig, ax = plt.subplots()
        ax.ticklabel_format(useOffset=False, style='plain')
        ax.set_xlabel('n')
        ax.set_ylabel('time (ms)')

        plt.grid(True)

        plt.plot(*line.linspace(), label=f'θ({complexity}) [{line:unicode}]')

        plt.scatter(self.x, self.y)
        ax.set_ylim(0)
        plt.legend()
        plt.show()
示例#2
0
    for h_i in h:
        f_error = np.append(f_error, [((h_i * Y_correct) / 2.0)])
        b_error = np.append(b_error, [((h_i * Y_correct) / 2.0)])
        c_error = np.append(c_error, [((h_i * h_i * d_correct(x)) / 6)])

    return f_error, b_error, c_error


##################################

fig, ax = plt.subplots()
ax.axhline(y=0, color='k')

p = Polynomial([2.0, 1.0, -6.0, -2.0, 2.5, 1.0])
data = p.linspace(domain=[-2.4, 1.5])
ax.plot(data[0], data[1], label='Function')

p_prime = p.deriv(1)
data2 = p_prime.linspace(domain=[-2.4, 1.5])
ax.plot(data2[0], data2[1], label='Derivative')

ax.legend()

##################################

h = 1
fig, bx = plt.subplots()
bx.axhline(y=0, color='k')

x = np.linspace(-2.0, 1.3, 50, endpoint=True)
exa=p([1,2,3])
print(exa.deriv(1))

import matplotlib.pyplot as plt
from numpy.polynomial import Chebyshev as T
x = np.linspace(-1, 1, 100)
#x= np.linspace(-2,2,100)
for i in range(5):
    ax = plt.plot(x, T.basis(i)(x), lw=2, label="$T_%d$"%i)
plt.legend()
plt.show()



np.random.seed(11)
x = np.linspace(0, 2*np.pi, 20)
y = np.sin(x) + np.random.normal(scale=.1, size=x.shape)
p = T.fit(x, y, 5)
plt.plot(x, y, 'o')
xx, yy = p.linspace()
plt.plot(xx, yy, lw=2)
p.domain
p.window
plt.show()
print("polyvalues finding ")
polyval(1,[1,2,3])

from scipy.stats import alpha
a = 3.57
mean, var, skew, kurt = alpha.stats(a, moments='mvsk')