The code works fine. But I want to include the convergence criterion which is as follows:
if the equation is written in the form $x=g(x)$, then condition of convergence is: $g'(x)<1$.
Note that: $g(x)=\sqrt [3]{3\,x-1}$ and $g'(x)=\left( 3\,x-1 \right) ^{-2/3}$
Please modify my code for convergence.
/* g (x) = (3x - l)^(l/3 ), x0=5 */
/* Fixed po int of Iteration Method */
#include<stdio.h>
#include<conio.h>
#include<math.h>
float g(float x)
{
return(pow((3*x-1), (.3333 )));
}
void main()
{
int n, i ;
float x0 ,xl ;
clrscr() ;
printf ("Enter xO , n");
scanf ("%f%d" ,&x0,&n);
for (i= 1;i<=n;i++ )
{
xl=g(x0);
printf("\t\t i=%d \t\t x1=%f\n\n", i,xl);
if(fabs (xl-x0)<.0001)
break ;
else
x0=xl;
}
printf ("The root is %£ ", xl);
getch();
}
Cleaned the code a bit, and used another function $g(x) = (x^3 + 1)/3$ and $g'(x) = x^2$. So as long as you start in $|x|<1$ convergence will work
This is a test