1import matplotlib.pyplot
as plt
6 "output/relative_error/RK4/",
7 "output/relative_error/euler/",
22 "Relative error for the RK4 method",
23 "Relative error for the forward Euler method"
29 fig1, axs1 = plt.subplots(2,1)
30 for i, (dir, title)
in enumerate(list(zip(directories, titles))):
32 for label, file
in zip(labels, files):
33 with open(dir+file)
as f:
35 t = np.linspace(0, 50, len(lines))
36 r = np.array([float(line.strip())
for line
in lines])
37 max_err.append(max(r))
38 axs1[i].plot(t, r, label=label)
40 axs1[i].set(xlabel=
r"t $(\mu s)$", ylabel =
r"relative_error $(\mu m)$")
42 axs1[i].set_title(title)
44 conv_rate = 1/3 * sum([np.log2(max_err[i+1]/max_err[i])/np.log2(.5)
for i
in range(3)])
45 print(f
"{methods[i]}: {conv_rate}")
47 fig1.savefig(
"../latex/images/phase_space_2_particles_x.pdf")
50if __name__ ==
"__main__":