/*CSEMATTER.BLOGSPOT.IN
program to implement newton raphson method*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define f(x) (x*x*x*x-x-10)
#define f1(x) (4*x*x*x-1)
void main()
{
int maxitr,itr;
float h,x1,x0;
clrscr();
printf("enter value");
scanf("%f",&x0);
printf("enter value of maxitr");
scanf("%d",&maxitr);
for(itr=1;itr<maxitr;itr++)
{h=f(x0)/f1(x0);
x1=x0-h;
if(fabs(h)<0.0001)
{printf("the root is %fafter %d iteration",x1,itr);
itr=-1;
break;}
else
x0=x1;
}
if(itr!=-1)
printf("no. of iteration are not sufficient");
getch();
}
/*output:enter value 2
enter value of maxitr:6
the root is 1.855585 after 4 iterations*/
program to implement newton raphson method*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define f(x) (x*x*x*x-x-10)
#define f1(x) (4*x*x*x-1)
void main()
{
int maxitr,itr;
float h,x1,x0;
clrscr();
printf("enter value");
scanf("%f",&x0);
printf("enter value of maxitr");
scanf("%d",&maxitr);
for(itr=1;itr<maxitr;itr++)
{h=f(x0)/f1(x0);
x1=x0-h;
if(fabs(h)<0.0001)
{printf("the root is %fafter %d iteration",x1,itr);
itr=-1;
break;}
else
x0=x1;
}
if(itr!=-1)
printf("no. of iteration are not sufficient");
getch();
}
/*output:enter value 2
enter value of maxitr:6
the root is 1.855585 after 4 iterations*/
No comments:
Post a Comment