diff --git a/methodes-spectrales/main.py b/methodes-spectrales/main.py index f95e367f66d048950146fe76b8e2e147e7a35124..058037a3d6284d42b55a343e08335e464863e322 100644 --- a/methodes-spectrales/main.py +++ b/methodes-spectrales/main.py @@ -34,13 +34,13 @@ def run_simulation(L, u0, dt, timesteps, nu=1): def wrap_simulation(L, N, dt=0.05, tmax=200, nu=1): x = linspace(0, L, N) - time_values = linspace(0, 200, int(tmax / dt)+1) + time_values = linspace(0, tmax, int(tmax / dt)+1) s = run_simulation(L, cos(2*pi/L * x) + 0.1 * cos(4*pi/L * x), dt, len(time_values)-1, nu=nu) return x, time_values, s # define a few constants -x, time_values, s = wrap_simulation(100, 1024) +x, time_values, s = wrap_simulation(100, 1024, nu=1) # pick a nice color for the plot colormap = plt.get_cmap("jet") # print the values @@ -71,10 +71,13 @@ def test_multiple_Ls(nu=1): # Plot A as a function of L for nu = 1 Ls, As, critical_L = test_multiple_Ls(1) plt.plot(Ls, As) +plt.xlabel("L") +plt.ylabel("A") plt.show() # Now find the critical value for multiple nus nus_exp = linspace(-0.5, 1.75, 20) +# nu between e^-0.5 and e^1.75 nus = exp(nus_exp) # use a log scale critical_Ls = zeros(nus.shape) for i, nu in enumerate(nus): @@ -89,7 +92,7 @@ from sklearn.linear_model import LinearRegression reg = LinearRegression().fit(log(nus).reshape(-1, 1), log(critical_Ls)) # we fit the logs # because we fitted the logs, we have the predict with the log, then take the exp() plt.plot(nus, exp(reg.predict(log(nus).reshape(-1, 1))), label="Linear Regression (slope = %f)" % reg.coef_) -plt.xlabel("$nu$") +plt.xlabel("$\\nu$") plt.ylabel("Critical L") plt.xscale("log") plt.yscale("log")