diff --git a/latex/assignment_1.pdf b/latex/assignment_1.pdf index bd95441..22dc022 100644 Binary files a/latex/assignment_1.pdf and b/latex/assignment_1.pdf differ diff --git a/latex/images/analytical_solution.pdf b/latex/images/analytical_solution.pdf index f874a22..18f05d2 100644 Binary files a/latex/images/analytical_solution.pdf and b/latex/images/analytical_solution.pdf differ diff --git a/latex/images/problem10.pdf b/latex/images/problem10.pdf index 0c7e50a..8c658db 100644 Binary files a/latex/images/problem10.pdf and b/latex/images/problem10.pdf differ diff --git a/latex/images/problem7.pdf b/latex/images/problem7.pdf index f205805..d9fbd30 100644 Binary files a/latex/images/problem7.pdf and b/latex/images/problem7.pdf differ diff --git a/latex/images/problem8_a.pdf b/latex/images/problem8_a.pdf index ae76581..1a326ec 100644 Binary files a/latex/images/problem8_a.pdf and b/latex/images/problem8_a.pdf differ diff --git a/latex/images/problem8_b.pdf b/latex/images/problem8_b.pdf index a0c4a77..023c75a 100644 Binary files a/latex/images/problem8_b.pdf and b/latex/images/problem8_b.pdf differ diff --git a/latex/images/problem8_c.pdf b/latex/images/problem8_c.pdf index 5f884db..294107f 100644 Binary files a/latex/images/problem8_c.pdf and b/latex/images/problem8_c.pdf differ diff --git a/src/analyticPlot.cpp b/src/analyticPlot.cpp index 07c932a..965b481 100644 --- a/src/analyticPlot.cpp +++ b/src/analyticPlot.cpp @@ -7,7 +7,7 @@ #include #define RANGE 1000 -#define FILENAME "analytical_solution.txt" +#define FILENAME "output/analytical_solution.txt" double u(double x); void generate_range(std::vector &vec, double start, double stop, int n); diff --git a/src/funcs.hpp b/src/funcs.hpp index 0d4a96e..ba8f9e3 100644 --- a/src/funcs.hpp +++ b/src/funcs.hpp @@ -4,7 +4,9 @@ #include #include -#define PRECISION 20 +#define PRECISION 8 + +#define N_STEPS_EXP 7 double f(double x); diff --git a/src/generalAlgorithm.cpp b/src/generalAlgorithm.cpp index b6ee8d9..92a7f0a 100644 --- a/src/generalAlgorithm.cpp +++ b/src/generalAlgorithm.cpp @@ -33,7 +33,7 @@ void general_algorithm_main() int steps; double step_size; - for (int i = 0; i < 6; i++) { + for (int i = 0; i < N_STEPS_EXP; i++) { steps = std::pow(10, i+1); step_size = 1./(double) steps; @@ -58,7 +58,7 @@ void general_algorithm_error() int steps; double step_size, abs_err, rel_err, u_i, v_i; - for (int i=0; i < 7; i++) { + for (int i=0; i < N_STEPS_EXP; i++) { steps = std::pow(10, i+1); step_size = 1./(double) steps; diff --git a/src/main.cpp b/src/main.cpp index bc742ab..e9c593d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,7 +20,7 @@ void timing() { ofile.open("output/timing.txt"); // Timing - for (int i=1; i <= 6; i++) { + for (int i=1; i < N_STEPS_EXP; i++) { n_steps = std::pow(10, i); clock_t g_1, g_2, s_1, s_2; double g_res = 0, s_res = 0; diff --git a/src/plot_analytic_solution.py b/src/plot_analytic_solution.py index 31ba66f..3223154 100644 --- a/src/plot_analytic_solution.py +++ b/src/plot_analytic_solution.py @@ -6,7 +6,7 @@ def main(): x = [] v = [] - with open('analytical_solution.txt') as f: + with open('output/analytical_solution.txt') as f: for line in f: a, b = line.strip().split() x.append(float(a)) diff --git a/src/plot_general_alg.py b/src/plot_general_alg.py index c4dd455..8f8a07f 100644 --- a/src/plot_general_alg.py +++ b/src/plot_general_alg.py @@ -4,8 +4,7 @@ import numpy as np analytical_func = lambda x: 1 - (1 - np.exp(-10))*x - np.exp(-10*x) def main(): - fig, ax = plt.subplots() - for i in range(6): + for i in range(7): x = [] y = [] x.append(0.) @@ -20,12 +19,12 @@ def main(): x.append(1.) y.append(0.) - ax.plot(x, y, label=f"n$_{{steps}} = 10^{i+1}$") + plt.plot(x, y, label=f"n$_{{steps}} = 10^{i+1}$") x = np.linspace(0, 1, 1001) - ax.plot(x, analytical_func(x), label=f"u$_{{exact}}$") - ax.legend() - fig.savefig("../latex/images/problem7.pdf") + plt.plot(x, analytical_func(x), label=f"u$_{{exact}}$") + plt.legend() + plt.savefig("../latex/images/problem7.pdf") if __name__ == "__main__": main() diff --git a/src/plot_general_alg_error.py b/src/plot_general_alg_error.py index fdc9cb2..cc1ce97 100644 --- a/src/plot_general_alg_error.py +++ b/src/plot_general_alg_error.py @@ -4,10 +4,7 @@ import matplotlib.pyplot as plt # plt.rc('font', family='serif') def main(): - fig_a, ax_a = plt.subplots() - fig_b, ax_b = plt.subplots() - fig_c, ax_c = plt.subplots() - for i in range(6): + for i in range(7): x = [] abs_err = [] rel_err = [] @@ -19,16 +16,25 @@ def main(): abs_err.append(float(abs_err_i)) rel_err.append(float(rel_err_i)) - ax_a.plot(x, abs_err, label=f"n$_{{steps}} = 10^{i+1}$") - ax_b.plot(x, rel_err, label=f"n$_{{steps}} = 10^{i+1}$") + plt.figure(1) + plt.plot(x, abs_err, label=f"n$_{{steps}} = 10^{i+1}$") + plt.figure(2) + plt.plot(x, rel_err, label=f"n$_{{steps}} = 10^{i+1}$") - ax_c.plot(i+1, max(rel_err), marker="o", markersize=10) + plt.figure(3) + plt.plot(i+1, max(rel_err), marker="o", markersize=10) - ax_a.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.) - ax_b.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.) - fig_a.savefig("../latex/images/problem8_a.pdf", bbox_inches="tight") - fig_b.savefig("../latex/images/problem8_b.pdf", bbox_inches="tight") - fig_c.savefig("../latex/images/problem8_c.pdf", bbox_inches="tight") + plt.figure(1) + plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.) + plt.figure(2) + plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.) + + plt.figure(1) + plt.savefig("../latex/images/problem8_a.pdf", bbox_inches="tight") + plt.figure(2) + plt.savefig("../latex/images/problem8_b.pdf", bbox_inches="tight") + plt.figure(3) + plt.savefig("../latex/images/problem8_c.pdf", bbox_inches="tight") if __name__ == "__main__": main() diff --git a/src/specialAlgorithm.cpp b/src/specialAlgorithm.cpp index 0d43112..8a918fc 100644 --- a/src/specialAlgorithm.cpp +++ b/src/specialAlgorithm.cpp @@ -33,7 +33,7 @@ void special_algorithm_main() int steps; double sub_sig, main_sig, sup_sig, step_size; - for (int i = 0; i < 6; i++) { + for (int i = 0; i < N_STEPS_EXP; i++) { steps = std::pow(10, i+1); step_size = 1./(double) steps; build_g_vec(steps, g_vec); diff --git a/src/timing.py b/src/timing.py index 63b7457..695a9b5 100644 --- a/src/timing.py +++ b/src/timing.py @@ -1,5 +1,4 @@ import matplotlib.pyplot as plt -import numpy as np def main(): fig, ax = plt.subplots() @@ -14,11 +13,11 @@ def main(): gen_alg.append(float(gen_i)) spec_alg.append(float(spec_i)) - ax.plot(x, gen_alg, label=f"General algorithm") - ax.plot(x, spec_alg, label=f"Special algorithm") + plt.plot(x, gen_alg, label=f"General algorithm") + plt.plot(x, spec_alg, label=f"Special algorithm") - ax.legend() - fig.savefig("../latex/images/problem10.pdf") + plt.legend() + plt.savefig("../latex/images/problem10.pdf") if __name__ == "__main__": main()