#include "stdio.h"
#include "conio.h"
#include "iostream.h"
#include "time.h"
#include "math.h"

#define E 0.001

double f(double x) {
return (0.1 * x * x - x * log(x));
};

double f_(double x) {
return (0.2 * x - log(x) - 1);
};

double Module(double x) {
if (x < 0) return (x * (-1));
return x;
}

double Itteraciya(double x0) {

double x1 = f(x0) + x0;

// cout << "f(" << x0 << ") = " << x1 <<
// "\t DELTA = " << Module(x0 - x1) <<
// "\t delta = " << Module(x0 - x1) / x0 << '\n';

if (Module(x0 - x1) > E) return Itteraciya(x1);

return x0;
}

double Delenie2(double a, double b) {

if (a > b) {
a *= b;
b = a / b;
a = a / b;
}

float x0 = (b + a) / 2;

// cout << "f(" << x0 << ") = " << f(x0) << "\t \t |a - b| = " << b - a << '\n';

if ((Module(f(x0)) < E) || ((b - a) < E)) return x0;

if ((f(a) * f(x0)) <= 0) x0 = Delenie2(a, x0);
else x0 = Delenie2(x0, b);

return x0;
};

double Newton(double x0, int n) {
double x1 = x0 - f(x0) / f_(x0);

if (n == 10) return x1;

return Newton(x1, n + 1);
}

int main () {

cout << '\n';
cout << "Temp..." << '\n';

time_t start_time = time(NULL);

double x = Itteraciya(0.5);
cout << "x = " << x << "\t f(x) = " << f(x) << '\n';

x = Delenie2(0.5, 3);
cout << "x = " << x << "\t f(x) = " << f(x) << '\n';

x = Newton(1, -10);
cout << "x = " << x << "\t f(x) = " << f(x) << '\n';

cout << "Time to work (sec.): " << time(NULL) - start_time << '\n';
return 1;
};

Сайт управляется системой uCoz