Q.This program is to solve y=x2-25.
#include<
#include<
#include<>
float x0,x1,f0,f1,f01,epsilon,delta,m;
int i,n;
float f(float a)
{
float b;
b=a*a-25;
return b;
}
float g(float c)
{
float d;
d=2*c;
return d;
}
float fun11()
{
printf("\nSlope too small. x0=%f, f0 =%f, f0'=%f0,i=%d\n",x0,f0,f01,i);
exit(1);
}
float fun13()
{
printf("\n%d %f %f %f %f %f",i+1,x0,x1,f0,f01,m);
printf("\n\nConvergent solution at %d iteration as x= %f\n",i,x1);
exit(1);
}
int main()
{
printf("Enter the values of x0,epsilon, delta, n\n");
scanf("%f%f%f%d",&x0,&epsilon,&delta,&n);
printf("Iteration x0 x1 f(x0) f'(x0) |(x1-x0)/x1|\n");
for(i=0;i<=n-1;i++)
{
f0=f(x0);
f01=g(x0);
if((fabs(f01))<=delta)
{
fun11();
}
x1=(x0-(f0/f01));
m=fabs((x1-x0)/x1);
if(m<=epsilon)
{
fun13();
}
printf("\n%d %f %f %f %f %f",i+1,x0,x1,f0,f01,m);
x0=x1;
}
printf("Slope too small x0= %f,f0=%f,f0'=%f,i=%d\n",x0,f0,f01,i);
return 0;
}
Nov 18, 2008
Newton Raphson Method
Posted by
bikash pradhan
at
8:16 AM
Subscribe to:
Post Comments (Atom)
Search
Programs
- backward difference formula c program code (1)
- Bisection Method c program code (1)
- Cramers rule (1)
- False position (1)
- Forward Difference Formula c program code (1)
- Gauss Seidal Method c program code (1)
- Guass Elimination Method c program code (1)
- Method of Successive Approximation c program code (1)
- Newton Raphson Method c program code (1)
- Newton's Backward Interpolation Formula c program code (1)
- Newton's Forward Interpolation Formula c program code (1)
- Regula Falsi on False Position Method c program code (1)
- Simpson's 1/3 Rule c program code (1)
- Simpson's Simpsons' 3/8 rule c program code (1)
- Trapezoidal Rule C program code (1)
0 comments:
Post a Comment