IITDU Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Newton-Raphson method in C

2 posters

Go down

C Newton-Raphson method in C

Post by BIT0216-Habib Wed Mar 09, 2011 4:06 pm

Hi guys,
I have implemented newton-raphson method in C. I am giving the code here for all of you.
Code:

#include<stdio.h>
#include<math.h>
#define e .00001
#define F(x) (x)*(x)-3*(x)+2
#define Fd(x) 2*(x)-3

int main(void){
    float x1,x2,f,fd,root;
    x1=2.333;
    f=F(x1);
    fd=Fd(x1);

    again: 
          printf("x1: %f\t",x1);
          x2 = x1-(f/fd);
          printf("x2: %f\n",x2);
          if(fabs(x2-x1)>e){
                  x1=x2;
                  f=F(x1);
                  fd=Fd(x1);
                  goto again;                 
          }else root = x2;
    printf("The root is: %f\n",root);

    float equvalue = F(root);
    printf("Value of F(root) is: %f",equvalue);
    return 0;

}

If you find any problem you can post here.
BIT0216-Habib
BIT0216-Habib
Administrator-RC

Course(s) :
  • BIT

Blood Group : O+
Posts : 217
Points : 458

Back to top Go down

C Re: Newton-Raphson method in C

Post by BIT0122-Amit Wed Mar 09, 2011 9:31 pm

good work Smile You can also check out this topic we made when we were in your stage.

[You must be registered and logged in to see this link.]
BIT0122-Amit
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

https://iitdu.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum