diff --git a/bab8/contoh_081.py b/bab8/contoh_081.py deleted file mode 100755 index 47c5182..0000000 --- a/bab8/contoh_081.py +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env python - -""" -contoh_081.py - -PDP Laplace 2D - -SHSH -22/12/23 -""" - -import numpy as np -import matplotlib.pyplot as plt -plt.style.use("bmh") - -def inisialisasi_grid(ukuran, nilai_awal=0): - return np.full(ukuran, nilai_awal, dtype=float) - -def terapkan_kondisi_batas(U): - Un = 80 - Us = 20 - Uw = 20 - Ue = 0 - - U[-1, :] = Un # Dirichlet - U[0, :] = Us # Dirichlet - U[:, 0] = Uw # Dirichlet - U[:, -1] = Ue # Neumann - -def iterasi_laplace(U, V, dxy): - for i in range(1, U.shape[0]-1, dxy): - for j in range(1, U.shape[1]-1, dxy): - U[i, j] = (U[i-1, j] + U[i+1, j] + U[i, j-1] + U[i, j+1]) / 4 - -def laplace_2d(): - # buat mesh - X, Y = np.meshgrid(np.arange(0, 50), np.arange(0, 50)) - - # inisialisasi - U = inisialisasi_grid((50, 50)) - V = np.copy(U) - - # kondisi - kondisi batas - terapkan_kondisi_batas(U) - - # pengaturan iterasi - dxy = 1 - imax = 1e4 - - # iterasi - ii = 0 - while ii < imax: - iterasi_laplace(U, V, dxy) - ii += 1 - galat = np.linalg.norm(U - V) / np.linalg.norm(U) - - np.copyto(V, U) - - if galat < 0.0001: - break - - return X, Y, U - -def plot_kontur(X, Y, U): - # plot kontur - kontur = plt.contourf(X, Y, U, 25, cmap="coolwarm") - - # menambahkan garis-garis nilai pada kontur plot - plt.contour(X, Y, U, colors='black', linestyles='dashed', linewidths=0.5) - - # menambahkan color bar dengan label - colorbar = plt.colorbar(kontur, label=r'T($^\circ$C)') - - # menambahkan label sumbu x dan y - plt.xlabel('$x$', fontsize=16) - plt.ylabel('$y$', fontsize=16) - plt.savefig("../gambar/gambar081.png", dpi=250) - -if __name__ == "__main__": - X, Y, U = laplace_2d() - plot_kontur(X, Y, U) diff --git a/bab8/contoh_082.py b/bab8/contoh_082.py deleted file mode 100644 index f5ed2ae..0000000 --- a/bab8/contoh_082.py +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env python - -""" -contoh_081.py - -PDP Kuantum - -SHSH -23/12/23 -""" - -import numpy as np -import matplotlib.pyplot as plt -plt.style.use("bmh") - -def atur_profil_energi_potensial(x, L, V0): - V = np.zeros_like(x) - V[(x > L / 3) & (x < 2 * L / 3)] = V0 - return V - -def atur_hamiltonian(jml_titik, dx, V): - H = np.zeros((jml_titik, jml_titik)) - H[np.diag_indices(jml_titik)] = 2 / dx**2 + V - H[np.arange(1, jml_titik), np.arange(0, jml_titik - 1)] = -1 / dx**2 - H[np.arange(0, jml_titik - 1), np.arange(1, jml_titik)] = -1 / dx**2 - return H - -def main(): - # Konstanta - h_bar = 1.0 # Konstanta Planck tereduksi - m = 1.0 # Massa partikel - L = 10.0 # Lebar sumur potensial - V0 = 50.0 # Tinggi penghalang potensial - jml_titik = 500 # Jumlah titik spasial - dx = L / (jml_titik - 1) # Ukuran langkah spasial - - # Diskritisasi koordinat spasial - x = np.linspace(0, L, jml_titik) - - # Atur profil energi potensial - V = atur_profil_energi_potensial(x, L, V0) - - # Atur matriks Hamiltonian - H = atur_hamiltonian(jml_titik, dx, V) - - # Hitung eigenvalues dan eigenvectors - eigenvalues, eigenvectors = np.linalg.eigh(H) - - # Plot energi potensial dan beberapa fungsi gelombang pertama - plt.plot(x, V, label='Energi Potensial') - for i in range(3): - plt.plot(x, eigenvalues[i] + eigenvectors[:, i], label=f'Mode Eigen {i+1}') - - plt.xlabel('$x$', fontsize=16) - plt.ylabel('Energi / Fungsi Gelombang', fontsize=16) - plt.legend() - plt.savefig("../gambar/gambar082.png", dpi=250) - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/gambar/gambar081.png b/gambar/gambar081.png deleted file mode 100644 index 590660d..0000000 Binary files a/gambar/gambar081.png and /dev/null differ diff --git a/gambar/gambar082.png b/gambar/gambar082.png deleted file mode 100644 index 396ced1..0000000 Binary files a/gambar/gambar082.png and /dev/null differ