ModSim: Added graph to assignment 2.2 and 2.3

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