Commit 55549caa authored by Taddeüs Kroes's avatar Taddeüs Kroes

Fixed Newton-Raphson header file.

parent f5e46532
......@@ -2,7 +2,7 @@
#define MAX_STEPS 1000
double newton_raphson(func_ptr f, func_ptr df, double x_start, int *steps) {
double newton_raphson(func_ptr f, func_ptr df, double x_start, unsigned int *steps) {
double x = x_start, last_x = x - 1;
for( *steps = 0; x != last_x; (*steps)++ ) {
......
......@@ -6,15 +6,22 @@
#define EPSILON 1e-11
double quad(double x) {
double f(double x) {
return x * x - 2;
}
double df(double x) {
return 2 * x;
}
int main(void) {
unsigned int steps;
printf("Square root of 2 using bisection method: %.11f (%d steps)\n",
bisec(&quad, 1.4, 1.5, EPSILON, &steps), steps);
bisec(&f, 1.4, 1.5, EPSILON, &steps), steps);
printf("Square root of 2 using newton_raphson method: %.11f (%d steps)\n",
newton_raphson(&f, &df, 1.4, &steps), steps);
return 0;
}
......@@ -35,7 +35,7 @@ double df3(double x) {
}
int main(void) {
int steps;
unsigned int steps;
double root;
if( !isnan(root = newton_raphson(&f2, &df2, 1000000, &steps)) )
......
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