Develop #14
@ -2,10 +2,10 @@ import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
def main():
|
||||
directories = {
|
||||
directories = [
|
||||
"output/relative_error/RK4/",
|
||||
"output/relative_error/euler/",
|
||||
}
|
||||
]
|
||||
files = [
|
||||
"4000_steps.txt",
|
||||
"8000_steps.txt",
|
||||
@ -22,8 +22,12 @@ def main():
|
||||
"Relative error for the RK4 method",
|
||||
"Relative error for the forward Euler method"
|
||||
]
|
||||
methods = [
|
||||
"rk4",
|
||||
"euler"
|
||||
]
|
||||
fig1, axs1 = plt.subplots(2,1)
|
||||
for i, (dir, title) in enumerate(zip(directories, titles)):
|
||||
for i, (dir, title) in enumerate(list(zip(directories, titles))):
|
||||
max_err = []
|
||||
for label, file in zip(labels, files):
|
||||
with open(dir+file) as f:
|
||||
@ -34,16 +38,13 @@ def main():
|
||||
axs1[i].plot(t, r, label=label)
|
||||
|
||||
axs1[i].set(xlabel=r"t $(\mu s)$", ylabel = r"relative_error $(\mu m)$")
|
||||
|
||||
|
||||
axs1[i].legend()
|
||||
axs1[i].set_title(title)
|
||||
|
||||
conv_rate = 1/3 * sum([np.log10(max_err[i+1]/max_err[i])/np.log10(.5) for i in range(3)])
|
||||
print(conv_rate)
|
||||
conv_rate = 1/3 * sum([np.log2(max_err[i+1]/max_err[i])/np.log2(.5) for i in range(3)])
|
||||
print(f"{methods[i]}: {conv_rate}")
|
||||
|
||||
plt.show()
|
||||
# fig1.savefig("../latex/images/phase_space_2_particles_x.pdf")
|
||||
fig1.savefig("../latex/images/phase_space_2_particles_x.pdf")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Loading…
Reference in New Issue
Block a user