描述
我开发了一种算法,实现了 Newton-Raphson 方法来找到五次函数的根。我必须反映的结果是303.6
。但是,我的实施未能达到标准。
数据
参数
g = 9.81; Ds = 0.198; uj = 805.9; W = 0.0557;
方程
0.024*((g Ds/uj^2)^(1/3)) (Y^(5/3)) + 0.2*(Y^(2/3)) - ((2.85/W)^(2/ 3)) = 0
其中导数为Y
:
(0.04*d^(1/3)⋅g(1/3)⋅y^(2/3)) / u(2/3) + 2/15*y^(1/3)
解决根为Y
代码
import java.lang.*;
public class InvokeNewton {
public static void main(String argv[]) {
double del = 1e-5,
double xx = 0 ;
double dx =0,
double x= Math.PI/2;
int k = 0;
while (Math.abs(xx-x) > del && k<10 && f(x)!=0) {
dx = f(x)/d(x);
xx=x;
x =x - dx;
k++;
System.out.println("Iteration number: " + k);
System.out.println("Root obtained: " + x);
System.out.println("Estimated error: " + Math.abs(xx-x));
}
}
// Method to provide function f(x)
public static double f(double x) {
return 0.024*(Math.pow(g * Ds / Math.pow(uj, 2.0),(1.0/3.0)) * (Math.pow(Y,5.0/3.0))+ 0.2*(Math.pow(Y,2.0/3.0)) - (Math.pow((2.85/W)(2.0/3.0))));
}
// Method to provide the derivative f'(x).
public static double d(double x) {
return (0.04*Math.pow(Ds,1.0/3.0)*Math.pow(Y,2.0/3.0)) / Math.pow*uj,2.0/3.0) + 2 / 15*Math.pow(Y,1.0/3.0);
}
}
输出
Iteration number: 1
Root obtained: 3.65373153496716
Estimated error: 2.0829352081722634
Iteration number: 2
Root obtained: 5.2246000232674215
Estimated error: 1.5708684883002615
Iteration number: 3
Root obtained: 6.618389759316356
Estimated error: 1.3937897360489346
Iteration number: 4
Root obtained: 7.906164279270034
Estimated error: 1.287774519953678
Iteration number: 5
Root obtained: 9.119558352547333
Estimated error: 1.213394073277299
Iteration number: 6
Root obtained: 10.27633029334909
Estimated error: 1.1567719408017574
Iteration number: 7
Root obtained: 11.387769167896339
Estimated error: 1.1114388745472485
Iteration number: 8
Root obtained: 12.461641418739712
Estimated error: 1.0738722508433725
Iteration number: 9
Root obtained: 13.503592201954325
Estimated error: 1.041950783214613
Iteration number: 10
Root obtained: 14.517895007865569
Estimated error: 1.0143028059112442
方程和导数已经过检查和双重检查,但是我仍然没有得到想要的输出