here is i trying to solve eq. - (e(x) - 4*x*x) by fixed point iteration. i took g(X) = x +/- (e^x)^(0.5) but on running the execution never stop and run on.... .what i do for bringing the roots of g(X).
What I have tried:
here is i trying to solve eq. - (e(x) - 4*x*x) by fixed point iteration. i took g(X) = x +/- (e^x)^(0.5) but on running the execution never stop and run on.... .what i do for bringing the roots of g(X).
#include<stdio.h>
#include<math.h>
double g(double x){
double result = 0.0;
result = x + pow(exp(x)/0.25 ,0.5);
return result;
}
double g1(double z){
double result1 = 0.0;
result1 = 1 + pow(exp(z)/0.0625 , 0.5);
return result1;
}
double mode(double z){
if(z<0)
return -z;
else return z;
}
int main(){
double x0,x1;
int i=1;
do{
printf("Input the approximate value:(x0)\n");
scanf("%lf",&x0);
if(mode(g1(x0))<1){
break;
}
else {
printf("RE-input the approx. value as g'(x0) is greater than 1.\n");
continue;
}
}while(1);
x1 = g(x0);
double abserr,ord,abserr0;
abserr = ord = 0;
printf("Iteration x(i) |g'(xi)| f(xi) AbsERROR ORDER\n");
printf("%d\t%lf\t%lf\t%lf\t%lf\t%lf\n",i,x0,mode(g1(x0)),g(x0),abserr,ord);
while(mode(x1-x0)>0.001){
abserr = x1-x0;
ord = log(mode(abserr0))/log(mode(abserr));
x0 = x1;
x1 = g(x0);
abserr0 = abserr;
printf("%d\t%lf\t%lf\t%lf\t%lf\t%lf\n",i,x0,g1(x0),g(x0),abserr,ord);
i++;
}
double answer = x1;
printf("Answer = %lf\n", x1);
return 0;
}