Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- double f(double x){
- return x*x+x-1;
- }
- double fp(double x){
- return 2*x+1;
- }
- int main(){
- int i;
- double eps0,epsx,x0,x1,f0,f1;
- eps0=1e-4;
- epsx=1e-4;
- printf("Podaj punkt startowy");
- scanf("%lf", &x0);
- x1 = x0 -1;
- f0 = f(x0);
- i=64;
- while (i && (fabs(x1 - x0) > epsx) && (fabs(f0) >eps0)){
- f1 = fp(x0);
- if(fabs(f1) < eps0){
- printf("zly punkt startowy");
- i=0; break;
- }
- x1 = x0;
- x0 = x0 - f0 / f1;
- f0 = f(x0);
- if(!(--i)) printf("przekroczono limit obiegow");
- }
- if(i) printf("x0= %lf",x0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement