Compare commits
No commits in common. "main" and "coryab/final-run" have entirely different histories.
main
...
coryab/fin
16
README.md
16
README.md
@ -10,29 +10,29 @@ Make sure that you are inside the **src** directory before compiling the code.
|
||||
|
||||
Now you can execute the command shown under to compile:
|
||||
|
||||
```
|
||||
´´´
|
||||
make
|
||||
```
|
||||
´´´
|
||||
|
||||
This will create object files and link them together into 2 executable files.
|
||||
These files are called **main** and **analyticPlot**.
|
||||
To run them, you can simply use the commands below:
|
||||
|
||||
```
|
||||
´´´
|
||||
./main
|
||||
```
|
||||
´´´
|
||||
|
||||
```
|
||||
´´´
|
||||
./analyticPlot
|
||||
```
|
||||
´´´
|
||||
|
||||
## How to generate plots
|
||||
|
||||
For generating the plots, there are 4 Python scripts.
|
||||
You can run each one of them by using this command:
|
||||
|
||||
```
|
||||
´´´
|
||||
python <PythonFile>
|
||||
```
|
||||
´´´
|
||||
|
||||
The plots will be saved inside **latex/images**.
|
||||
|
||||
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.
@ -1,8 +1,3 @@
|
||||
\section*{Problem 10}
|
||||
|
||||
% Time and show result, and link to relevant files
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
\includegraphics[width=0.7\linewidth]{images/problem10.pdf}
|
||||
\caption{Timing of general algorithm vs. special for step sizes $n_{steps}$}
|
||||
\end{figure}
|
||||
@ -6,8 +6,6 @@ Point generator code: https://github.uio.no/FYS3150-G2-203/Project-1/blob/main/s
|
||||
|
||||
Plotting code: https://github.uio.no/FYS3150-G2-2023/Project-1/blob/main/src/analyticPlot.py
|
||||
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
\includegraphics[width=0.8\linewidth]{images/analytical_solution.pdf}
|
||||
\caption{Plot of the analytical solution $u(x)$.}
|
||||
\end{figure}
|
||||
Here is the plot of the analytical solution for $u(x)$.
|
||||
|
||||
\includegraphics[scale=.5]{analytical_solution.pdf}
|
||||
|
||||
@ -2,13 +2,8 @@
|
||||
|
||||
\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/main/src/generalAlgorithm.cpp
|
||||
The code can be found at https://github.uio.no/FYS3150-G2-2023/Project-1/blob/coryab/final-run/src/generalAlgorithm.cpp
|
||||
|
||||
\subsection*{b)}
|
||||
Increasing the number of steps results in an approximation close to the exact solution.
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
\includegraphics[width=0.8\linewidth]{images/problem7.pdf}
|
||||
\caption{Plot showing the numeric solution of $u_{approx}$ for $n_{steps}$ and the exact solution $u_{exact}$.}
|
||||
\end{figure}
|
||||
|
||||
\includegraphics{problem7}
|
||||
|
||||
@ -1,27 +1,3 @@
|
||||
\section*{Problem 8}
|
||||
|
||||
%link to relvant files and show plots
|
||||
\subsection*{a)}
|
||||
Increasing number of steps result in a decrease of absolute error.
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
\includegraphics[width=0.8\linewidth]{images/problem8_a.pdf}
|
||||
\caption{Absolute error for different step sizes $n_{steps}$.}
|
||||
\end{figure}
|
||||
|
||||
\subsection*{b)}
|
||||
Increasing number of steps also result in a decrease of absolute error.
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
\includegraphics[width=0.8\linewidth]{images/problem8_b.pdf}
|
||||
\caption{Relative error for different step sizes $n_{steps}$.}
|
||||
\end{figure}
|
||||
|
||||
\subsection*{c)}
|
||||
Increasing number of steps result in a decrease of maximum relative error, up to a certain number of steps. At $n_{steps} \approx 10^{5}$ the maximumrelative error increase.
|
||||
This can be related to loss of numerical precicion when step size is small.
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
\includegraphics[width=0.7\linewidth]{images/problem8_c.pdf}
|
||||
\caption{Maximum relative error for each step sizes $n_{steps}$.}
|
||||
\end{figure}
|
||||
@ -7,7 +7,7 @@
|
||||
#include <iomanip>
|
||||
|
||||
#define RANGE 1000
|
||||
#define FILENAME "output/analytical_solution.txt"
|
||||
#define FILENAME "analytical_solution.txt"
|
||||
|
||||
double u(double x);
|
||||
void generate_range(std::vector<double> &vec, double start, double stop, int n);
|
||||
|
||||
@ -4,9 +4,7 @@
|
||||
#include <armadillo>
|
||||
#include <cmath>
|
||||
|
||||
#define PRECISION 8
|
||||
|
||||
#define N_STEPS_EXP 7
|
||||
#define PRECISION 20
|
||||
|
||||
double f(double x);
|
||||
|
||||
|
||||
@ -33,7 +33,7 @@ void general_algorithm_main()
|
||||
int steps;
|
||||
double step_size;
|
||||
|
||||
for (int i = 0; i < N_STEPS_EXP; i++) {
|
||||
for (int i = 0; i < 6; 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 < N_STEPS_EXP; i++) {
|
||||
for (int i=0; i < 7; 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 < N_STEPS_EXP; i++) {
|
||||
for (int i=1; i <= 6; 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('output/analytical_solution.txt') as f:
|
||||
with open('analytical_solution.txt') as f:
|
||||
for line in f:
|
||||
a, b = line.strip().split()
|
||||
x.append(float(a))
|
||||
|
||||
@ -4,7 +4,7 @@ import numpy as np
|
||||
analytical_func = lambda x: 1 - (1 - np.exp(-10))*x - np.exp(-10*x)
|
||||
|
||||
def main():
|
||||
for i in range(7):
|
||||
for i in range(6):
|
||||
x = []
|
||||
y = []
|
||||
x.append(0.)
|
||||
@ -19,10 +19,10 @@ def main():
|
||||
x.append(1.)
|
||||
y.append(0.)
|
||||
|
||||
plt.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)
|
||||
plt.plot(x, analytical_func(x), label=f"u$_{{exact}}$")
|
||||
plt.plot(x, analytical_func(x), label="analytical plot")
|
||||
plt.legend()
|
||||
plt.savefig("../latex/images/problem7.pdf")
|
||||
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# plt.rc('text', usetex=True)
|
||||
# plt.rc('font', family='serif')
|
||||
|
||||
def main():
|
||||
for i in range(7):
|
||||
fig, axs = plt.subplots(1)
|
||||
for i in range(6):
|
||||
x = []
|
||||
abs_err = []
|
||||
rel_err = []
|
||||
@ -16,25 +14,16 @@ def main():
|
||||
abs_err.append(float(abs_err_i))
|
||||
rel_err.append(float(rel_err_i))
|
||||
|
||||
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}$")
|
||||
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")
|
||||
print(max(rel_err))
|
||||
axs[2].plot(i+1, max(rel_err), marker="o", markersize=10)
|
||||
|
||||
plt.figure(3)
|
||||
plt.plot(i+1, max(rel_err), marker="o", markersize=10)
|
||||
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")
|
||||
fig.2
|
||||
|
||||
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 < N_STEPS_EXP; i++) {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
steps = std::pow(10, i+1);
|
||||
step_size = 1./(double) steps;
|
||||
build_g_vec(steps, g_vec);
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
def main():
|
||||
x = []
|
||||
@ -12,8 +13,8 @@ def main():
|
||||
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"Special algorithm")
|
||||
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")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user