Fixed point : A point, say, s is called a fixed point if it satisfies the equation x = g(x).
ALGORITHM:
- Given an equation f(x) = 0.
- Convert f(x) = 0 into the form x = g(x).
- Let the initial guess be xi.
- Do xi+1 = g(xi).
- If |xi+1 - xi| < tolerance, root = xi+1, Else go to step 4.
- STOP.
#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float x)
{
return ((pow(x,2)+2)/3); /* x2 -3x+2 = 0 */
}
void main()
{
float x0,x1=0,tmp,eps=0.001;
int iteration=0;
printf("Enter initial guess: ");
scanf("%f",&x0);
do
{
tmp=x1;
x1=f(x0);
iteration++;
printf("\n%d\t%f",iteration,x1);
x0=x1;
}while(fabs(tmp-x1)>eps);
printf("\n\n Real root=%0.4f\n Iteration=%d",x1,iteration);
getch();
No comments:
Post a Comment