Created
February 8, 2025 06:48
-
-
Save silgon/0e3c84b9c746bd222ddd8060326147b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
h = 1 | |
p = np.pi*1/3 | |
m = np.arange(1,101) | |
A_m = 2*h*np.sin(m*p)/(m**2*p*(np.pi-p)) | |
x = np.linspace(0,np.pi,150) | |
# f = A_m* np.sin(m[np.newaxis,:]*x[:,np.newaxis]) | |
f = A_m * np.sin(np.outer(x,m)) | |
f=f.T | |
# plt.plot(x, f[:, 0], label='First column', alpha=0.7) | |
# plt.plot(x, f[:, 1], label='Second column', alpha=0.7) | |
plt.plot(x, f[:2, :].sum(1), label='Sum of first 2 columns', alpha=0.7) | |
plt.plot(x, f[:5, :].sum(1), label='Sum of first 5 columns', alpha=0.7) | |
plt.plot(x, f[:9, :].sum(1), label='Sum of first 9 columns', alpha=0.7) | |
plt.plot(x, f.sum(1), label='Sum of all columns', alpha=0.7) | |
plt.legend() | |
plt.show() | |
t = np.linspace(0,2*np.pi,200) | |
tmp = np.cos(np.outer(t,m)) | |
f_full = f[np.newaxis,:,:]*tmp[:,:,np.newaxis] | |
X, T = np.meshgrid(x, t) | |
Z = f_full.sum(1) | |
fig = plt.figure() | |
ax = fig.add_subplot(111, projection='3d') | |
ax.plot_surface(X, T, Z, cmap='viridis') # Use a colormap for better visualization | |
ax.set_xlabel('X-axis') | |
ax.set_ylabel('T-axis') | |
ax.set_zlabel('Z-axis (f_full sum)') | |
ax.set_title('3D Surface Plot of f_full') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment