Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1.
- #include<stdio.h>
- #include<math.h>
- #define E 0.001
- #define f(x) x*x-4*x-10
- #define g(x) 2*x-4
- int main(){
- float x0,x1,x2,f0,g0,root;
- int i=1;
- printf("Using Newton Raphson Method to find root of the equation (x*x)-4*x-10\n");
- printf("\n Enter the value of x0");
- scanf("%f",&x0);
- printf("step\tx0\tx1\tf0\tg0\n");
- b:f0=f(x0);
- g0=g(x0);
- x1=x0-(f0/g0);
- printf("%d\t %4f\t %4f\t %4f \t%4f \n",i,x0,x1,f0,g0);
- i++;
- if(fabs((x1-x0)/x1)<=E){
- root=x1;
- printf("The root is %4f",root);
- goto c;}
- else {
- x0=x1;
- goto b ;
- }
- c:
- getch();
- }
- 2.
- #include<stdio.h>
- #include<math.h>
- #define E 0.0001
- #define f(x) sin(x)-1+x*x
- #define g(x) cos(x)+2*x
- int main(){
- float x0,x1,x2,f0,g0,root;
- int i=1;
- printf("Using Newton Raphson Method to find root of the equation (x*x)-4*x-10\n");
- printf("\n Enter the value of x0 :");
- scanf("%f",&x0);
- printf("Step \t x0\t\t x1\t\t f0\t\tg0\n");
- b:f0=f(x0);
- g0=g(x0);
- x1=x0-(f0/g0);
- printf("%d\t %4f\t %4f\t %4f \t%4f \n",i,x0,x1,f0,g0);
- i++;
- if(fabs((x1-x0)/x1)<=E){
- root=x1;
- printf("The root is %4f",root);
- goto c;}
- else {
- x0=x1;
- goto b ;
- }
- c:
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement