ModSim: Added graph to assignment 2.2 and 2.3

parent 4a712f13
No preview for this file type
......@@ -5,8 +5,6 @@
#include "newton_raphson.h"
#include "regula_falsi.h"
#define EPSILON 1e-11
double f(double x) {
return x * x - 2;
}
......@@ -15,20 +13,32 @@ double df(double x) {
return 2 * x;
}
int main(void) {
unsigned int steps = 0;
int main(int argc, char *argv[]) {
unsigned int steps, i, begin, end;
double tmp, epsilon;
if( argc != 3 ) {
printf("Usage: %s BEGIN END\n", argv[0]);
return 1;
}
begin = atoi(argv[1]);
end = atoi(argv[2]);
double tmp = bisec(&f, 1, 2, EPSILON, &steps);
printf("Square root of 2 using bisection method: %.20f (%d steps)\n",
tmp, steps);
for( i = begin; i <= end; i++) {
epsilon = pow(10, -1.0 * i);
tmp= bisec(&f, 1, 2, epsilon, &steps);
printf("Sqrt(2) using bisection: %.20f (%d steps; epsilon=%.0e)\n",
tmp, steps, epsilon);
tmp = newton_raphson(&f, &df, 1.4, EPSILON, &steps, 100000);
printf("Square root of 2 using Newton-Raphson method: %.20f (%d steps)\n",
tmp, steps);
tmp = newton_raphson(&f, &df, 1.4, epsilon, &steps, 100000);
printf("Sqrt(2) using Newton-Raphson: %.20f (%d steps; epsilon=%.0e)\n",
tmp, steps, epsilon);
tmp = regula_falsi(&f, 1, 2, EPSILON, &steps, 100000);
printf("Square root of 2 using the Regula Falsi method: %.20f (%d steps)\n",
tmp, steps);
tmp = regula_falsi(&f, 1, 2, epsilon, &steps, 100000);
printf("Sqrt(2) using Regula Falsi: %.20f (%d steps; epsilon=%.0e)\n",
tmp, steps, epsilon);
}
return 0;
}
......@@ -94,7 +94,11 @@ beoogde nauwkeurigheid.
\section{Benadering van $\sqrt{2}$} % {{{
\label{sec:benadering van sqrt 2}
\begin{figure}[H]
\centering
\includegraphics[width=12cm]{sqrt}
\caption{A}
\end{figure}
% }}}
......
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