#include <stdio.h>
#include <math.h>
double newton_method_quartic(double x0, int max_iter, double tol) {
double x = x0;
for (int i = 0; i < max_iter; i++) {
double fx = x * x * x * x - 7;
double dfx = 4 * x * x * x;
double x_next = x - fx / dfx;
if (fabs(x_next
- x
) < tol
) { return x_next;
}
x = x_next;
}
return x;
}
int main() {
double initial_guess = 2.0; // 初期値
int max_iterations = 100; // 最大反復回数
double tolerance = 1e-7; // 許容誤差
double root = newton_method_quartic(initial_guess, max_iterations, tolerance);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXRoLmg+Cgpkb3VibGUgbmV3dG9uX21ldGhvZF9xdWFydGljKGRvdWJsZSB4MCwgaW50IG1heF9pdGVyLCBkb3VibGUgdG9sKSB7CiAgICBkb3VibGUgeCA9IHgwOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBtYXhfaXRlcjsgaSsrKSB7CiAgICAgICAgZG91YmxlIGZ4ID0geCAqIHggKiB4ICogeCAtIDc7CiAgICAgICAgZG91YmxlIGRmeCA9IDQgKiB4ICogeCAqIHg7CiAgICAgICAgZG91YmxlIHhfbmV4dCA9IHggLSBmeCAvIGRmeDsKICAgICAgICBpZiAoZmFicyh4X25leHQgLSB4KSA8IHRvbCkgewogICAgICAgICAgICByZXR1cm4geF9uZXh0OwogICAgICAgIH0KICAgICAgICB4ID0geF9uZXh0OwogICAgfQogICAgcmV0dXJuIHg7Cn0KCmludCBtYWluKCkgewogICAgZG91YmxlIGluaXRpYWxfZ3Vlc3MgPSAyLjA7IC8vIOWIneacn+WApAogICAgaW50IG1heF9pdGVyYXRpb25zID0gMTAwOyAvLyDmnIDlpKflj43lvqnlm57mlbAKICAgIGRvdWJsZSB0b2xlcmFuY2UgPSAxZS03OyAvLyDoqLHlrrnoqqTlt64KCiAgICBkb3VibGUgcm9vdCA9IG5ld3Rvbl9tZXRob2RfcXVhcnRpYyhpbml0aWFsX2d1ZXNzLCBtYXhfaXRlcmF0aW9ucywgdG9sZXJhbmNlKTsKICAgIHByaW50Zigi4oicNyDiiYggJS4xMGZcbiIsIHJvb3QpOwoKICAgIHJldHVybiAwOwp9