Merge coryab/final-run into janitaws/plot-and-latex
This commit is contained in:
commit
bc5436cf1e
Binary file not shown.
BIN
latex/images/problem7.pdf
Normal file
BIN
latex/images/problem7.pdf
Normal file
Binary file not shown.
Binary file not shown.
@ -1,3 +1,9 @@
|
||||
\section*{Problem 7}
|
||||
|
||||
\subsection*{a)}
|
||||
% Link to relevant files on gh and possibly add some comments
|
||||
The code can be found at https://github.uio.no/FYS3150-G2-2023/Project-1/blob/coryab/final-run/src/generalAlgorithm.cpp
|
||||
|
||||
\subsection*{b)}
|
||||
|
||||
\includegraphics{problem7}
|
||||
|
||||
@ -4,6 +4,10 @@ double f(double x) {
|
||||
return 100*std::exp(-10*x);
|
||||
}
|
||||
|
||||
double u(double x) {
|
||||
return 1. - (1. - std::exp(-10.))*x - std::exp(-10.*x);
|
||||
}
|
||||
|
||||
void build_g_vec(int n_steps, arma::vec& g_vec) {
|
||||
g_vec.resize(n_steps-1);
|
||||
|
||||
|
||||
@ -4,10 +4,12 @@
|
||||
#include <armadillo>
|
||||
#include <cmath>
|
||||
|
||||
#define PRECISION 8
|
||||
#define PRECISION 20
|
||||
|
||||
double f(double x);
|
||||
|
||||
double u(double x);
|
||||
|
||||
void build_g_vec(int n_steps, arma::vec& g_vec);
|
||||
|
||||
void build_arrays(
|
||||
|
||||
@ -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 < 6; i++) {
|
||||
for (int i=0; i < 7; i++) {
|
||||
steps = std::pow(10, i+1);
|
||||
step_size = 1./(double) steps;
|
||||
|
||||
@ -69,16 +69,16 @@ void general_algorithm_error()
|
||||
ofile.open("output/error/out_" + std::to_string(steps) + ".txt");
|
||||
|
||||
for (int j=0; j < v_vec.n_elem; j++) {
|
||||
u_i = f(step_size*(j+1));
|
||||
u_i = u(step_size*(j+1));
|
||||
v_i = v_vec(j);
|
||||
abs_err = u_i - v_i;
|
||||
ofile << std::setprecision(PRECISION) << std::scientific
|
||||
<< step_size*(j+1) << ","
|
||||
<< std::setprecision(PRECISION) << std::scientific
|
||||
<< std::log10(std::abs(u_i - v_i)) << ","
|
||||
<< std::log10(std::abs(abs_err)) << ","
|
||||
<< std::setprecision(PRECISION) << std::scientific
|
||||
<< std::log10(std::abs((u_i - v_i)/u_i)) << std::endl;
|
||||
<< std::log10(std::abs(abs_err/u_i)) << std::endl;
|
||||
}
|
||||
ofile.close();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,12 +4,12 @@ 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):
|
||||
for i in range(6):
|
||||
x = []
|
||||
y = []
|
||||
x.append(0.)
|
||||
y.append(0.)
|
||||
with open(f"output/problem7/out_{10**(i+1)}.txt", "r") as f:
|
||||
with open(f"output/general/out_{10**(i+1)}.txt", "r") as f:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
x_i, y_i = line.strip().split(",")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user