y-msiny-x=0,其中m=0.9,0<=x<=π,x所属区间分成30等份,对每个x用牛顿法求y。
Java代码:
public class Newton {
public static final double EPSILON = 1e-15;
private static double f(double x, double y) {
return y - 0.9 * Math.sin(y) - x;
}
// y - 0.9*Math.sin(y) - x,x取固定值,对y求导后为 1 - 0.9 * Math.cos(y)
private static double d(double y) {
return 1 - 0.9 * Math.cos(y);
}
public static double root(double x) {
double y = 1;
while (Math.abs(f(x, y) / d(y)) > EPSILON) {
y = y - f(x, y) / d(y);
}
return y;
}
public static void main(String[] args) {
double xStep = Math.PI / 30;
for (int i = 0; i <= 30; i++) {
double x = xStep * i;
double y = root(x);
System.out.println("x: " + x + ", y=: "+ y);
}
}
}