Commit d27d0314 by Jigyasa Watwani

log-log plots

parent 471b4c07
...@@ -45,7 +45,7 @@ def advection_diffusion(Nx, L, Nt, tmax, D): ...@@ -45,7 +45,7 @@ def advection_diffusion(Nx, L, Nt, tmax, D):
# parameters # parameters
Nx, L, D, tmax = 32, 1, 0.1, 0.25 Nx, L, D, tmax = 32, 1, 0.1, 0.25
nt_array = np.array([50, 100, 200]) nt_array = np.array([5, 10, 15, 20, 25, 50, 100, 200, 400, 800, 1600])
dt_array = tmax/nt_array dt_array = tmax/nt_array
mesh = df.IntervalMesh(Nx, 0, L) mesh = df.IntervalMesh(Nx, 0, L)
x = mesh.coordinates()[:, 0] x = mesh.coordinates()[:, 0]
...@@ -63,7 +63,7 @@ for i in range(0, len(nt_array)): ...@@ -63,7 +63,7 @@ for i in range(0, len(nt_array)):
c = advection_diffusion(Nx, L, nt_array[i], tmax, D) c = advection_diffusion(Nx, L, nt_array[i], tmax, D)
error[i] = np.max(np.abs(c[-1] - c_exact[-1])) error[i] = np.max(np.abs(c[-1] - c_exact[-1]))
print('Max error for dt=0.0005 at t=0.25 is',error[0]) print('dt,t,error=', tmax/400, tmax, error[-3])
popt, pcov = curve_fit(linear_func, np.log(dt_array), np.log(error)) popt, pcov = curve_fit(linear_func, np.log(dt_array), np.log(error))
print('The slope of the graph of log(error) vs log(dt) is', popt[0]) print('The slope of the graph of log(error) vs log(dt) is', popt[0])
fig, ax = plt.subplots(1) fig, ax = plt.subplots(1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment