Новое значение: HelloWorld!
Задача 5.1. Создайте класс, содержащий метод, который с точностью до Eps = рассчитывает таблицу значений функции вещественной переменной х.
0<x≤2,
Результаты работы сравните с результатом расчета соответствующего метода класса Math.
public class MyClass {
static final double eps=1e-4;
public static double mylog(double x) {
double sum=x-1,c=x-1;
int n=1;
while(Math.abs(c/n)>eps){
c*=-(x-1); sum+=c/++n; }
return sum;
}
public static void main(String[] args) {
System.out.printf("-------------------------------%n");
System.out.printf("| x | mylog(x)| log(x) |%n");
System.out.printf("-------------------------------%n");
for(double x=0.1;x<=2;x+=(2-0.1)/5){
System.out.printf("|%8.4f |%8.4f |%8.4f |%n", x, mylog(x), Math.log(x));}
System.out.printf("-------------------------------%n");
}}
Результат:
-------------------------------
| x | my_log(x)| log(x) |
-------------------------------
| 0,1000 | -2,3019 | -2,3026 |
| 0,4800 | -0,7339 | -0,7340 |
| 0,8600 | -0,1508 | -0,1508 |
| 1,2400 | 0,2151 | 0,2151 |
| 1,6200 | 0,4824 | 0,4824 |
| 2,0000 | 0,6931 | 0,6931 |
-------------------------------