#include <stdio.
h>
#include <math.h>
// Función f(x)
double f(double x) {
return pow(x, 4) - 2;
}
// Derivada f'(x)
double df(double x) {
return 4 * pow(x, 3);
}
int main() {
double x0 = 1.0, x1;
double error, tol;
int max_iter, i = 0;
int opcion;
printf("Metodo de Newton-Raphson\n");
printf("1. Por numero de iteraciones\n");
printf("2. Por error relativo\n");
printf("Seleccione una opcion: ");
scanf("%d", &opcion);
if (opcion == 1) {
printf("Ingrese numero de iteraciones: ");
scanf("%d", &max_iter);
for (i = 0; i < max_iter; i++) {
x1 = x0 - f(x0) / df(x0);
printf("Iteracion %d: x = %.6f\n", i+1, x1);
x0 = x1;
}
} else if (opcion == 2) {
printf("Ingrese tolerancia de error (%%): ");
scanf("%lf", &tol);
do {
x1 = x0 - f(x0) / df(x0);
error = fabs((x1 - x0) / x1) * 100;
printf("Iteracion %d: x = %.6f, error = %.6f%%\n", i+1, x1, error);
x0 = x1;
i++;
} while (error > tol);
} else {
printf("Opcion no valida\n");
}
printf("\nRaiz aproximada: %.6f\n", x1);
return 0;
}