Make some changes
This commit is contained in:
parent
bb01d6fa79
commit
0edaae5b3f
19
src/plot_analytic_solution.py
Normal file
19
src/plot_analytic_solution.py
Normal file
@ -0,0 +1,19 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
def main():
|
||||
FILENAME = "../latex/images/analytical_solution.pdf"
|
||||
x = []
|
||||
v = []
|
||||
|
||||
with open('analytical_solution.txt') as f:
|
||||
for line in f:
|
||||
a, b = line.strip().split()
|
||||
x.append(float(a))
|
||||
v.append(float(b))
|
||||
|
||||
plt.plot(x, v)
|
||||
plt.savefig(FILENAME)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
30
src/plot_general_alg.py
Normal file
30
src/plot_general_alg.py
Normal file
@ -0,0 +1,30 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
analytical_func = lambda x: 1 - (1 - np.exp(-10))*x - np.exp(-10*x)
|
||||
|
||||
def main():
|
||||
for i in range(2):
|
||||
x = []
|
||||
y = []
|
||||
x.append(0.)
|
||||
y.append(0.)
|
||||
with open(f"output/problem7/out_{10**(i+1)}.txt", "r") as f:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
x_i, y_i = line.strip().split(",")
|
||||
x.append(float(x_i))
|
||||
y.append(float(y_i))
|
||||
|
||||
x.append(1.)
|
||||
y.append(0.)
|
||||
|
||||
plt.plot(x, y, label=f"n_steps={10**(i+1)}")
|
||||
|
||||
x = np.linspace(0, 1, 1001)
|
||||
plt.plot(x, analytical_func(x), label="analytical plot")
|
||||
plt.legend()
|
||||
plt.savefig("../latex/images/problem7.pdf")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
25
src/plot_general_alg_error.py
Normal file
25
src/plot_general_alg_error.py
Normal file
@ -0,0 +1,25 @@
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
def main():
|
||||
_, axs = plt.subplots(2)
|
||||
for i in range(6):
|
||||
x = []
|
||||
abs_err = []
|
||||
rel_err = []
|
||||
with open(f"output/error/out_{10**(i+1)}.txt", "r") as f:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
x_i, abs_err_i, rel_err_i = line.strip().split(",")
|
||||
x.append(float(x_i))
|
||||
abs_err.append(float(abs_err_i))
|
||||
rel_err.append(float(rel_err_i))
|
||||
|
||||
axs[0].plot(x, abs_err, label=f"abs_err {10**(i+1)} steps")
|
||||
axs[1].plot(x, rel_err, label=f"rel_err {10**(i+1)} steps")
|
||||
|
||||
axs[0].legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
|
||||
axs[1].legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
|
||||
plt.savefig("../latex/images/problem8.pdf", bbox_inches="tight")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
23
src/timing.py
Normal file
23
src/timing.py
Normal file
@ -0,0 +1,23 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
def main():
|
||||
x = []
|
||||
gen_alg = []
|
||||
spec_alg = []
|
||||
with open(f"output/timing.txt", "r") as f:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
x_i, gen_i, spec_i = line.strip().split(",")
|
||||
x.append(float(x_i))
|
||||
gen_alg.append(float(gen_i))
|
||||
spec_alg.append(float(spec_i))
|
||||
|
||||
plt.plot(x, gen_alg, label=f"general algorithm")
|
||||
plt.plot(x, spec_alg, label=f"general algorithm")
|
||||
|
||||
plt.legend()
|
||||
plt.savefig("../latex/images/problem10.pdf")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Reference in New Issue
Block a user