Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Numerical MethodsRSS Feeds

N-R METHOD

Posted By: Adalwolfa Fischer     Category: C Programming     Views: 3177

Write a program of N-R METHOD.

Code for N-R METHOD in C Programming

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define ESP 0.00001
#define F1(x) (x)*(x)*(x) - 5*(x) + 3
#define F2(x) 3*(x)*(x) - 5
void main()
{
  float x1,x2,f1,f2;
  clrscr();
  do
  {
  printf("\nEnter the value of x1: ");
  scanf("%f",&x1);
  }while(F1(x1) > 0);
  printf("\n______________________________________________\n");
  printf("\n    x1\t       f(x)\t f'(x)\t   x2");
  printf("\n______________________________________________\n");
  do
  {
  f1=F1(x1);
  f2=F2(x1);
  x2=x1-(f1/f2);
  printf("\n%f   %f   %f   %f ",x1,f1,f2,x2);
  x1=x2;
  getch();
  }while(F1(x2)>ESP);
printf("\n______________________________________________\n");
printf("\n\nApp.root = %f",x2);
getch();
}

/*
OUT PUT
---------

Enter the value of x1: 1

______________________________________________

x1 f(x) f'(x) x2
______________________________________________

1.000000 -1.000000 -2.000000 0.500000
0.500000 0.625000 -4.250000 0.647059
0.647059 0.035620 -3.743945 0.656573
0.656573 0.000176 -3.706736 0.656620
______________________________________________


App.root = 0.656620

*/
  
Share: 


Didn't find what you were looking for? Find more on N-R METHOD Or get search suggestion and latest updates.

Adalwolfa Fischer
Adalwolfa Fischer author of N-R METHOD is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!