Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
lab7_OOP 0.2
#include <stdlib.h> #include <stdio.h> #include <math.h> #include <float.h> double f1 (double x, double t) { if (x != 0.0) { return cos(t/x) - 2.0*sin(1.0/x) + 1.0/x; } else { printf("Помилка. Ділення на нуль. f1(%lf, %lf)\n", x, t); exit(-1); } } double f2 (double x, double t) { if (x > 0.0) { return sin(log(x)) - cos(log(x)) + t*log(x); } else { printf("Помилка. Ділення на нуль. f1(%lf, %lf)\n", x, t); exit(-1); } } double newton (double (*f)(double, double), double a, double b, double t, double eps ) { if (f != NULL) { double x0 = b; double x1 = x0; for (int i = 0; i <= 1000; ++i) { double y = f(b, t); double ydiff = (f(b+1e-10, t) - f(b, t))/1e-10; if (abs(ydiff) != 0.0) { printf("Помилка. Похідна дорівнює нулю. newton(%p, %lf, %lf, %lf, %lf)\n", f, a, b, t, eps); exit(-1); } x1 = x0 - y/ydiff; if(abs(x1 - x0)/abs(x1) < eps) { return x1; } x0 = x1; } printf("Помилка. Кількість ітерацій перевищила 1000. newton(%p, %lf, %lf, %lf, %lf)\n", f, a, b, t, eps); exit(-1); } else { printf("Помилка. Нульовий покажчик на функцію. newton(%p, %lf, %lf, %lf, %lf)\n", f, a, b, t, eps); exit(-1); } } int main(void) { printf("%lf", newton(f1, /*Цільова функція*/ 2.0, /*Перше обмеження, a*/ 6.0, /*Друге обмеження, b*/ 2.0, /*Параметер, t*/ 0.000000001 /*Точність*/ )); return 0; }
run
|
edit
|
history
|
help
0
Herout (67) - 5
UDP - Male/Velke pismena
POLE[radky][sloupce]
Sin(x) in C Teylor
Concatenate Strings
Tablero de ajedrez
lab7_OOP 0.3
cv2
Bucles: Triangulo asteriscos izquierdo
VKI_Mihalyk_3_3