На
#include <iostream>
#include <iomanip>
#include <cmath>
#include <array>
inline double exactDerivative(double x) {
double x2 = x * x;
return (2 * (x2 - 1) - 2 * x * (1 + 2 * x)) / std::pow((x2 - 1), 2);
}
inline double function(double x) {
return (1 + 2 * x) / (x * x - 1);
}
int main() {
double x;
std::cout << "Введите значение X: ";
std::cin >> x;
const std::array<double, 4> dxValues = {0.0001, 0.001, 0.01, 0.1};
double exact = exactDerivative(x);
std::cout << std::setw(10) << "DX"
<< std::setw(20) << "DY/DX"
<< std::setw(20) << "Exact"
<< std::setw(20) << "Error" << '\n';
for (const double& dx : dxValues) {
double dy = function(x + dx) - function(x);
double approxDerivative = dy / dx;
double error = std::abs(exact - approxDerivative);
std::cout << std::setw(10) << dx
<< std::setw(20) << approxDerivative
<< std::setw(20) << exact
<< std::setw(20) << error << '\n';
}
return 0;
}