15 lines
402 B
C
15 lines
402 B
C
#include <math.h>
|
|
#include <stdio.h>
|
|
#define EPSILON 0.0000001
|
|
#define f(x) ((352 * x * x * x) - (64 * x * x) + (198 * x) - 36)
|
|
double secant(double a, double b) {
|
|
double x1;
|
|
x1 = (a * f(b) - b * f(a)) / (f(b) - f(a));
|
|
if (f(x1) == 0 || fabs(a - b) < EPSILON)
|
|
return x1;
|
|
return secant(b, x1);
|
|
}
|
|
int main() {
|
|
printf("Root for f(x) = 352x^3 - 64x^2 + 198x - 36 is %lf", secant(1.6, -4));
|
|
}
|