ModSim: Added graph for fibonnaci assignment.

parent 801444b9
...@@ -15,4 +15,5 @@ plt.xscale('log') ...@@ -15,4 +15,5 @@ plt.xscale('log')
plt.xlabel('epsilon') plt.xlabel('epsilon')
plt.ylabel('steps') plt.ylabel('steps')
plt.grid(True) plt.grid(True)
plt.savefig('plot.pdf') plt.savefig('bisec.pdf')
...@@ -2,22 +2,37 @@ ...@@ -2,22 +2,37 @@
#include <stdio.h> #include <stdio.h>
void sequence(int n, int max_age) { void sequence(int n, int max_age) {
int i, mature = 0, int i;
died = 0;
long long mature = 0,
died = 0;
long long *new = malloc((n+1) * sizeof(long long));
printf("popu:");
int *new = malloc(n * sizeof(int));
new[0] = 1; new[0] = 1;
printf("1"); printf(" 1");
for( i = 1; i < n; i++ ) { for( i = 1; i < n; i++ ) {
died = i < max_age ? 0 : new[i - max_age]; died = i < max_age ? 0 : new[i - max_age];
new[i] = mature; new[i] = mature;
mature = mature + new[i - 1] - died; mature = mature + new[i - 1] - died;
printf(" %d", mature + new[i]); printf(" %lld", mature + new[i]);
} }
new[i] = mature;
puts(""); puts("");
//printf("diff: ");
//for( i = 1; i < n; i++ )
// printf(" %lld", new[i]);
//puts("");
free(new);
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
......
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 114 151 200 265 351 465 616 816
1 1 2 3 4 6 9 13 19 28 41 60 88 129 189 277 406 595 872 1278 1873 2745 4023 5896 8641
1 1 2 3 5 7 11 17 26 40 61 94 144 221 339 520 798 1224 1878 2881 4420 6781 10403 15960 24485
1 1 2 3 5 8 12 19 30 47 74 116 182 286 449 705 1107 1738 2729 4285 6728 10564 16587 26044 40893
1 1 2 3 5 8 13 20 32 51 81 129 205 326 518 824 1310 2083 3312 5266 8373 13313 21168 33657 53515
1 1 2 3 5 8 13 21 33 53 85 136 218 349 559 895 1433 2295 3675 5885 9424 15091 24166 38698 61969
1 1 2 3 5 8 13 21 34 54 87 140 225 362 582 936 1505 2420 3891 6257 10061 16178 26014 41830 67262
1 1 2 3 5 8 13 21 34 55 88 142 229 369 595 959 1546 2492 4017 6475 10437 16824 27119 43714 70464
import matplotlib.pyplot as plt
import re
data = [re.split('\s+', line)[:-1] for line in file('rabbit.log')]
for i in range(len(data)):
data.insert(i*2, range(len(data[0])))
plt.plot(*data)
plt.yscale('log')
plt.xlabel('generatie')
plt.ylabel('populatie')
plt.grid(True)
plt.savefig('rabbit.pdf')
...@@ -78,7 +78,7 @@ gelijk aan $1.114157142 \dots$, interessanter is echter de relatie tussen de ...@@ -78,7 +78,7 @@ gelijk aan $1.114157142 \dots$, interessanter is echter de relatie tussen de
nauwkeurigheid en het aantal stappen van de berekening: nauwkeurigheid en het aantal stappen van de berekening:
\begin{figure}[H] \begin{figure}[H]
\includegraphics[scale=.5]{plot} \includegraphics[width=12cm]{bisec}
\caption{Het verband tussen de nauwkeurigheid en het aantal stappen van de \caption{Het verband tussen de nauwkeurigheid en het aantal stappen van de
berekening is logaritmisch.} berekening is logaritmisch.}
\end{figure} \end{figure}
...@@ -185,4 +185,21 @@ sin & 0 & $8\pi$ & gauss & $-1.797258919631 \cdot 10^{-14}$ & $1.797258919 ...@@ -185,4 +185,21 @@ sin & 0 & $8\pi$ & gauss & $-1.797258919631 \cdot 10^{-14}$ & $1.797258919
% }}} % }}}
\section{Instelbare accuratie} % {{{
\label{sec:Instelbare accuratie}
% }}}
\section{Fibonnaci} % {{{
\label{sec:Fibonnaci}
\begin{figure}[H]
\centering
\includegraphics[width=12cm]{rabbit}
\caption{Groei van konijnenpopulatie voor verschillende maximum leeftijden (2
t/m 10 jaar).}
\end{figure}
% }}}
\end{document} \end{document}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment