Make small changes
This commit is contained in:
parent
b88a9027bc
commit
7d39248a15
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -7,7 +7,7 @@
|
||||
#include <iomanip>
|
||||
|
||||
#define RANGE 1000
|
||||
#define FILENAME "analytical_solution.txt"
|
||||
#define FILENAME "output/analytical_solution.txt"
|
||||
|
||||
double u(double x);
|
||||
void generate_range(std::vector<double> &vec, double start, double stop, int n);
|
||||
|
||||
@ -4,7 +4,9 @@
|
||||
#include <armadillo>
|
||||
#include <cmath>
|
||||
|
||||
#define PRECISION 20
|
||||
#define PRECISION 8
|
||||
|
||||
#define N_STEPS_EXP 7
|
||||
|
||||
double f(double x);
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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))
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user