From fd90a4d45d97188483d4ecbac9310d4b5959748f Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Wed, 26 May 2021 22:37:38 +0200 Subject: [PATCH] Tweak a little for the report --- methodes-spectrales/main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/methodes-spectrales/main.py b/methodes-spectrales/main.py index f95e367..058037a 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") -- GitLab