Newton Iteration
#include <iostream>#include<string.h>#include<math.h>using namespacestd;floatFfloatx) { return(Pow (x,3)-5*pow (x,2)+ -*x+ the);}floatF1 (floatx) { return(3*pow (x,2)-5*x+ -);}intMain () {//x*x*x-5*x*x+16*x+80; floatx=1, X1,y1,y2; CIN>>x; Do{x1=x; Y1=f (x); Y2=F1 (x1); X=x1-y1/Y2; } while(Fabs (X-X1) >=0.000001); cout<<x1<<Endl; System ("Pause"); return 0;}
If you want to calculate the root under 3, then the equation is x*x-3=0;
Fabs the absolute value of floating-point numbers
The equation is solved by the dichotomy method:
#include <iostream>#include<math.h>using namespacestd;DoubleFDoublex) { returnPow (x,x)-Ten;}intMain () {DoubleA=2, b=3, limit=0.00001; while((B-A) >limit) { if(f (a+b)/2) *f (b) <0) {a= (a+b)/2; } Else //Same numberb= (A+B)/2; } cout<<a<<" "<<b<<Endl; System ("Pause"); return 0;}
x^x=10;
Solution of equations, Newton iteration and dichotomy