-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp11.py
33 lines (27 loc) · 855 Bytes
/
p11.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
31
32
33
"""p11.py - Chebyshev differentiation of a smooth function"""
import numpy as np
from cheb import cheb
import matplotlib.pyplot as plt
plt.figure(figsize=(8, 6))
xx = np.arange(-1, 1.01, 0.01)
uu = np.exp(xx) * np.sin(5 * xx)
for n in [10, 20]:
D, x = cheb(n)
u = np.exp(x) * np.sin(5 * x)
plt.subplot(2, 2, 2 * (n // 10) - 1)
plt.plot(x, u, "k.", markersize=8)
plt.grid()
plt.plot(xx, uu, "k-", linewidth=0.75)
plt.xlim(-1, 1)
plt.ylim(-4, 2)
plt.yticks(np.arange(-4, 3, 2))
plt.title(f"$u(x)$, $N={n}$")
error = D @ u - np.exp(x) * (np.sin(5 * x) + 5 * np.cos(5 * x))
plt.subplot(2, 2, 2 * (n // 10))
plt.plot(x, error, "k.", markersize=8)
plt.grid()
plt.plot(x, error, "k-", linewidth=0.75)
plt.xlim(-1, 1)
plt.title(f"error in $u''(x)$, $N={n}$")
plt.tight_layout()
plt.show()