This method is also called "Tangent Method".
ALGORITHM:
ALGORITHM:
- START.
- Find the first order derivative f'(x) of the given non-linear equation f(x).
- Assume initial guess as x0.
- Find the next value from N-R formula as x=x0-f(x0)/f'(x0).
- If |x-x0|<accuracy, root = x, Else set x0=x and go to step 4.
- STOP.
#include<stdio.h>
#include<math.h>
#include<conio.h>
float f(float x)
{
return(3*x-cos(x)-1); /* 3x=cos(x)+1 */
}
float g(float y)
{
return(3+sin(y)); /* 3+sin(y) */
}
void main()
{
float x0,x=0,eps=0.001,tmp;
int iteration=0;
printf("\nEnter guess:");
scanf("%f",&x0);
do
{
tmp=x;
x=x0-(f(x0)/g(x0));
iteration++;
x0=x;
}while(fabs(tmp-x)>eps);
printf("Root = %.4f Iteration = %d",x,iteration);
getch();
No comments:
Post a Comment