Files
cmlab/1.c
Amneesh Singh be590b5cfd exp 1-6: init
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
2022-12-26 19:14:30 +05:30

16 lines
428 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)
#define f1(x) ((1056 * x * x) - (128 * x) + 198)
double newtonRaphson(double x) {
double h = f(x) / f1(x);
if (f(x) == 0 || fabs(h) < EPSILON)
return x;
return newtonRaphson(x - h);
}
int main() {
printf("Root for f(x) = 352x^3 - 64x^2 + 198x - 36 is %lf",
newtonRaphson(-4));
}