⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 metododenewton.cpp

📁 Topics Practices: Programming and Numerical Methods Practice 1: Introduction to C Practice 2
💻 CPP
字号:
//METODO DE NEWTON CON MINI ACOTACION// 
#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float x)
{     
      return (x*x)-2;
}      
float d_f(float x)
{     
      return 2*x;
}
main()
{     
      int iter_max,i;
      float x_0,x,x_prev,tol;
      printf("Ingrese el valor inicial \n ");
      scanf("%f",&x_0); //donde empiezo a trabajar la funcion
      printf("Ingrese el valor de la tolerancia\n");
      scanf("%f",&tol);
      iter_max=1000; //segunda proteccion por si llega a oscilar.
      x=x_0;
      x_prev=100*x_0; //para que entre al menos una vez al while.
      i=0;
      while(fabs(x-x_prev)>tol && i<=iter_max)
{     
      x_prev=x;
      x=x_prev-f(x_prev)/d_f(x_prev);
      printf("x=%f\n");
      ++i;
}
      printf(" La estimacion del valor de la raiz es %f\n",x);
      printf("La funcion en ese punto es %f");
getch();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -