###前提・実現したいこと
Newton法を使ってx^x-2の解を近似して出したい。
そこまではできたのだが、誤差eを弄っても解が一部分までしか出ない。
###発生している問題・エラーメッセージ
1.559610
###該当のソースコード
C
1#include <stdio.h> 2#include <math.h> 3 4double Newton(double x_0); 5double f(double x); 6double df(double x); 7 8int main(){ 9 10 double x_0; 11 double x_n; 12 13 x_0 = 2.0; 14 15 x_n = Newton(x_0); 16 17 printf("%f",x_n); 18 19 return 0; 20} 21 22double Newton(double x_0){ 23 24 25 double x,x_next; 26 27 x = x_0; 28 double e = 0.0001; 29 int flag = 1; 30 31 while(flag){ 32 33 x_next = x - f(x)/df(x); 34 35 if(fabs((x_next - x)/x)< e){ 36 flag = 0; 37 } 38 39 x = x_next; 40 } 41 return x_next; 42} 43 44double f(double x){ 45 46 double y; 47 48 y = pow(x,x) - 2.0; 49 50 return y; 51} 52 53double df(double x){ 54 55 double y; 56 57 y = pow(x,x)*( log(x) + 1.0 ); 58 59 return y; 60} 61
###試したこと
誤差eの桁をさらに0.000000..と増やしてみたものの、変化が現れない。
これが近似できる最も近い値なのでしょうか?
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/06/19 10:19 編集
2016/06/19 10:21 編集
2016/06/19 11:29