By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,831 Members | 1,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,831 IT Pros & Developers. It's quick & easy.

c program to implement newton raphson method for finding roots of a polynomial

P: 21
c program for newton raphson algorithm for finding roots of a polynomial
Oct 9 '06 #1
Share this Question
Share on Google+
6 Replies


10K+
P: 13,264
c program for newton raphson algorithm for finding roots of a polynomial
Why won't you try to write it yourself and then post at a more specific problem?
Oct 9 '06 #2

P: 21
how can i implement a c progran for newton raphson algorithm using a for loop?
Oct 9 '06 #3

Banfa
Expert Mod 5K+
P: 8,916
how can i implement a c progran for newton raphson algorithm using a for loop?
Please dont double post.

Please do have an attempt yourself first.



Do you know how the newton raphson method works?
Oct 9 '06 #4

P: 21
#include<stdio.h>
/Calculate j(10) from j(0)
int main()
{
int n;
double j=0.6;
printf("forward iterations\n");
printf("initial estimate:j(0)=%g\n",j);
for(n=1,n<=10,n++)
j=1-(j*n);
printf("j(%d)=%g\n",n,j);
}
return 0;
}
this code is not helping me find roots of( x*x-2).What do I need to change?
Oct 10 '06 #5

iknc4miles
P: 32
Ok, let me see if I understand your code.

I'm a numerical methods and modeling engineer so I should understand the Newton-Raphson Method to be:

j( i+1 ) = j( i ) - [ j( i )^2 - 2 ] / [ 2*j( i ) ] for the function f( j ) = (j*j - 2).

So, you should step i forward until f( j ) is within your tolerance of 0. Then your answer should be your last j.

Here's some pseudocode:

i = 0

while( absoluteValue( f( j ) ) > toleranceValue)
{
j = j - [ f( j ) ] / [ df( j ) ];
i++;
}
printOut("Root of Function is at %g After %d Iterations" j, i );

When you write this out in whatever language you want, should work.

- Miles
Oct 10 '06 #6

Banfa
Expert Mod 5K+
P: 8,916
Please DON'T double post (hmmm I seem to be repeating myself here)

Read This
Oct 10 '06 #7

Post your reply

Sign in to post your reply or Sign up for a free account.