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>
|
#include <iomanip>
|
||||||
|
|
||||||
#define RANGE 1000
|
#define RANGE 1000
|
||||||
#define FILENAME "analytical_solution.txt"
|
#define FILENAME "output/analytical_solution.txt"
|
||||||
|
|
||||||
double u(double x);
|
double u(double x);
|
||||||
void generate_range(std::vector<double> &vec, double start, double stop, int n);
|
void generate_range(std::vector<double> &vec, double start, double stop, int n);
|
||||||
|
|||||||
@ -4,7 +4,9 @@
|
|||||||
#include <armadillo>
|
#include <armadillo>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#define PRECISION 20
|
#define PRECISION 8
|
||||||
|
|
||||||
|
#define N_STEPS_EXP 7
|
||||||
|
|
||||||
double f(double x);
|
double f(double x);
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,7 @@ void general_algorithm_main()
|
|||||||
int steps;
|
int steps;
|
||||||
double step_size;
|
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);
|
steps = std::pow(10, i+1);
|
||||||
step_size = 1./(double) steps;
|
step_size = 1./(double) steps;
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ void general_algorithm_error()
|
|||||||
int steps;
|
int steps;
|
||||||
double step_size, abs_err, rel_err, u_i, v_i;
|
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);
|
steps = std::pow(10, i+1);
|
||||||
step_size = 1./(double) steps;
|
step_size = 1./(double) steps;
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@ void timing() {
|
|||||||
ofile.open("output/timing.txt");
|
ofile.open("output/timing.txt");
|
||||||
|
|
||||||
// Timing
|
// Timing
|
||||||
for (int i=1; i <= 6; i++) {
|
for (int i=1; i < N_STEPS_EXP; i++) {
|
||||||
n_steps = std::pow(10, i);
|
n_steps = std::pow(10, i);
|
||||||
clock_t g_1, g_2, s_1, s_2;
|
clock_t g_1, g_2, s_1, s_2;
|
||||||
double g_res = 0, s_res = 0;
|
double g_res = 0, s_res = 0;
|
||||||
|
|||||||
@ -6,7 +6,7 @@ def main():
|
|||||||
x = []
|
x = []
|
||||||
v = []
|
v = []
|
||||||
|
|
||||||
with open('analytical_solution.txt') as f:
|
with open('output/analytical_solution.txt') as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
a, b = line.strip().split()
|
a, b = line.strip().split()
|
||||||
x.append(float(a))
|
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)
|
analytical_func = lambda x: 1 - (1 - np.exp(-10))*x - np.exp(-10*x)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
fig, ax = plt.subplots()
|
for i in range(7):
|
||||||
for i in range(6):
|
|
||||||
x = []
|
x = []
|
||||||
y = []
|
y = []
|
||||||
x.append(0.)
|
x.append(0.)
|
||||||
@ -20,12 +19,12 @@ def main():
|
|||||||
x.append(1.)
|
x.append(1.)
|
||||||
y.append(0.)
|
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)
|
x = np.linspace(0, 1, 1001)
|
||||||
ax.plot(x, analytical_func(x), label=f"u$_{{exact}}$")
|
plt.plot(x, analytical_func(x), label=f"u$_{{exact}}$")
|
||||||
ax.legend()
|
plt.legend()
|
||||||
fig.savefig("../latex/images/problem7.pdf")
|
plt.savefig("../latex/images/problem7.pdf")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@ -4,10 +4,7 @@ import matplotlib.pyplot as plt
|
|||||||
# plt.rc('font', family='serif')
|
# plt.rc('font', family='serif')
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
fig_a, ax_a = plt.subplots()
|
for i in range(7):
|
||||||
fig_b, ax_b = plt.subplots()
|
|
||||||
fig_c, ax_c = plt.subplots()
|
|
||||||
for i in range(6):
|
|
||||||
x = []
|
x = []
|
||||||
abs_err = []
|
abs_err = []
|
||||||
rel_err = []
|
rel_err = []
|
||||||
@ -19,16 +16,25 @@ def main():
|
|||||||
abs_err.append(float(abs_err_i))
|
abs_err.append(float(abs_err_i))
|
||||||
rel_err.append(float(rel_err_i))
|
rel_err.append(float(rel_err_i))
|
||||||
|
|
||||||
ax_a.plot(x, abs_err, label=f"n$_{{steps}} = 10^{i+1}$")
|
plt.figure(1)
|
||||||
ax_b.plot(x, rel_err, label=f"n$_{{steps}} = 10^{i+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.)
|
plt.figure(1)
|
||||||
ax_b.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
|
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
|
||||||
fig_a.savefig("../latex/images/problem8_a.pdf", bbox_inches="tight")
|
plt.figure(2)
|
||||||
fig_b.savefig("../latex/images/problem8_b.pdf", bbox_inches="tight")
|
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
|
||||||
fig_c.savefig("../latex/images/problem8_c.pdf", bbox_inches="tight")
|
|
||||||
|
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__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@ -33,7 +33,7 @@ void special_algorithm_main()
|
|||||||
int steps;
|
int steps;
|
||||||
double sub_sig, main_sig, sup_sig, step_size;
|
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);
|
steps = std::pow(10, i+1);
|
||||||
step_size = 1./(double) steps;
|
step_size = 1./(double) steps;
|
||||||
build_g_vec(steps, g_vec);
|
build_g_vec(steps, g_vec);
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
fig, ax = plt.subplots()
|
fig, ax = plt.subplots()
|
||||||
@ -14,11 +13,11 @@ def main():
|
|||||||
gen_alg.append(float(gen_i))
|
gen_alg.append(float(gen_i))
|
||||||
spec_alg.append(float(spec_i))
|
spec_alg.append(float(spec_i))
|
||||||
|
|
||||||
ax.plot(x, gen_alg, label=f"General algorithm")
|
plt.plot(x, gen_alg, label=f"General algorithm")
|
||||||
ax.plot(x, spec_alg, label=f"Special algorithm")
|
plt.plot(x, spec_alg, label=f"Special algorithm")
|
||||||
|
|
||||||
ax.legend()
|
plt.legend()
|
||||||
fig.savefig("../latex/images/problem10.pdf")
|
plt.savefig("../latex/images/problem10.pdf")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user