Skip to content
Extraits de code Groupes Projets
Valider fd90a4d4 rédigé par Technici4n's avatar Technici4n
Parcourir les fichiers

Tweak a little for the report

parent 5a22a306
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -34,13 +34,13 @@ def run_simulation(L, u0, dt, timesteps, nu=1): ...@@ -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): def wrap_simulation(L, N, dt=0.05, tmax=200, nu=1):
x = linspace(0, L, N) 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) 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 return x, time_values, s
# define a few constants # 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 # pick a nice color for the plot
colormap = plt.get_cmap("jet") colormap = plt.get_cmap("jet")
# print the values # print the values
...@@ -71,10 +71,13 @@ def test_multiple_Ls(nu=1): ...@@ -71,10 +71,13 @@ def test_multiple_Ls(nu=1):
# Plot A as a function of L for nu = 1 # Plot A as a function of L for nu = 1
Ls, As, critical_L = test_multiple_Ls(1) Ls, As, critical_L = test_multiple_Ls(1)
plt.plot(Ls, As) plt.plot(Ls, As)
plt.xlabel("L")
plt.ylabel("A")
plt.show() plt.show()
# Now find the critical value for multiple nus # Now find the critical value for multiple nus
nus_exp = linspace(-0.5, 1.75, 20) 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 nus = exp(nus_exp) # use a log scale
critical_Ls = zeros(nus.shape) critical_Ls = zeros(nus.shape)
for i, nu in enumerate(nus): for i, nu in enumerate(nus):
...@@ -89,7 +92,7 @@ from sklearn.linear_model import LinearRegression ...@@ -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 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() # 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.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.ylabel("Critical L")
plt.xscale("log") plt.xscale("log")
plt.yscale("log") plt.yscale("log")
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter