Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # include <stdio.h>
- # include <math.h>
- double newton(double f(double), double xo, int cit, int numit) {
- if (numit == cit) return xo;
- xo -= (f(xo) / d(f, xo));
- return newton(f, xo, numit, ++cit);
- }
- double f(double x) {
- return 2*pow(x, 2) - 2;
- }
- double d(double f(double), double x) {
- double h = pow(10, -9);
- return (f(x+h) - f(x))/h;
- }
- int main() {
- printf("%f\n", newton(f, 2.0, 1, 5));
- return 0;
- }
- // debian@debian~/Documents/dev/c/calculo: gcc calculo.c -o calculo.o -lm;chmod +x calculo.o
- // debian@debian~/Documents/dev/c/calculo: ./calculo.o
- // 1.000000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement