Program #include<conio.h> #include<stdio.h> #include<math.h> #define f(x) ((5/x)+x)/2 #define e 0.0001 int main(vo...
Program
#include<conio.h>
#include<stdio.h>
#include<math.h>
#define f(x) ((5/x)+x)/2
#define e 0.0001
int main(void)
{
float x0,x1,f1 ;
int i=1;
clrscr();
printf("Using Fixed Point Method / Iterative Method to find root of x^2-5=0\n");
printf("Enter value for x0\n");
printf("x0: ");
scanf("%f",&x0);
printf("steps\tx0\tx1\n");
b:x1=f(x0);
printf("%d\t%.4f\t%.4f\n",i,x0,x1);
i++;
if(fabs((x1-x0)/x1)<=e)
{
printf("The root is %.4f",x1);
goto c;
}
else
{
x0=x1;
goto b;
}
c:
getch();
}
Output
How to solve using this method?
Third find value of function by substituting the value on derived equation and check for error criteria.
If not match the the resultant function value become x and repeat the same process i.e finding value of function.
If match print root.
#include<conio.h>
#include<stdio.h>
#include<math.h>
#define f(x) ((5/x)+x)/2
#define e 0.0001
int main(void)
{
float x0,x1,f1 ;
int i=1;
clrscr();
printf("Using Fixed Point Method / Iterative Method to find root of x^2-5=0\n");
printf("Enter value for x0\n");
printf("x0: ");
scanf("%f",&x0);
printf("steps\tx0\tx1\n");
b:x1=f(x0);
printf("%d\t%.4f\t%.4f\n",i,x0,x1);
i++;
if(fabs((x1-x0)/x1)<=e)
{
printf("The root is %.4f",x1);
goto c;
}
else
{
x0=x1;
goto b;
}
c:
getch();
}
Output
How to solve using this method?
First you have to derive function from the given function to find root. Here x^2-5=0 function is used and have to find its root so ((5/x)+x)/2=0 function is derived.
Second insert value for x.Third find value of function by substituting the value on derived equation and check for error criteria.
If not match the the resultant function value become x and repeat the same process i.e finding value of function.
If match print root.
COMMENTS