Wednesday, 5 December 2012

Newton-Raphson Method


       §       

PROGRAMMING IN C: ASSIGNMENT


PRATYUSH DAS
BEE 3RD YEAR
Electrical Engineering Department, Jadavpur University

-------Contents-------

         §         Gauss-elimination method
         §         Gauss-Seidel method
         §         Bisection method
         §         False position method
         §         Secant method
         §         Newton-Raphson method  ...............................................................................
......................................................................... 

/* Newton Raphson Method*/

#include<stdio.h>
#include<math.h>
#define f(x) (x*x*x-4*x-9) // any equation can be taken here
#define f1(x) (3*x*x-4)

void main()
{
      int itr,N;
      float h,x0,x1,err;
         printf("------------NEWTON-RAPHSON METHODOLOGY------------\n\n\n");
      printf("enter x0,allowed error,maximum iterations\n");
      scanf("%f %f %d",&x0,&err,&N);
         printf("\n\n");
      for(itr=1;itr<=N;itr++)
      {
      h=f(x0)/f1(x0);
      x1=x0-h;
      printf("iteration no. %3d  gives ,x= %9.6f\n",itr,x1);
      if(fabs(h)<err)
      {
      printf("after %3d iterations,""root is  \n    x=%8.6f\n",itr,x1);
      getch();
      exit(1);
      }
      x0=x1;
      }
      printf("iterations not sufficient, solution does not converge\n");
      getch();
}

ª       Results: (Newton-Raphson method)
 ------------NEWTON-RAPHSON METHODOLOGY-------
enter x0,allowed error,maximum iterations
2    .005    66
iteration no.   1  gives ,x=  3.125000
iteration no.   2  gives ,x=  2.768530
iteration no.   3  gives ,x=  2.708196
iteration no.   4  gives ,x=  2.706529
after   4 iterations,root is
    x=2.706529                                                                                                  

7 comments:

  1. Thanks to you too,for the appreciation..

    ReplyDelete
  2. thanks for letting me know that it helped you.. it will inspire me to continue posting

    ReplyDelete
  3. Favorite post having such an fantastic and useful informative content.
    Buy Business Term Paper

    ReplyDelete
  4. Very significant article for us ,I think the representation of this article is actually superb one. This is my first visit to your site. dissertation help

    ReplyDelete
  5. The assignment help Australia provides consultancy services for students in helping students getting the assistance they want to earn top grades.
    Assignment Help Australia

    ReplyDelete
  6. Hi,
    This is a nice post you have shared a great information here.
    Top Quality Essay

    ReplyDelete