Finding Coefficients of a polynomial, roots are provided from command line

Reply

Join Date: Sep 2008
Posts: 3
Reputation: jits_aps90 is an unknown quantity at this point 
Solved Threads: 0
jits_aps90 jits_aps90 is offline Offline
Newbie Poster

Finding Coefficients of a polynomial, roots are provided from command line

 
0
  #1
Sep 13th, 2008
Some numbers like 1,2,3,4,.... are provided from the command line. Considering them to be roots of a polynomial of that degree< equal to number of roots > , i was trying to find the coefficients of the constructed polynomial, i was using the concept of multiplication of two single degree polynomials.
for e.g if the numbers are 1,2 and3.
the P(x) == (x-1)(x-2)(x-3).
so if give 1 and 2 in the command line. the sample output should be 1 , -3, 2.
Please help me......
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 2
Reputation: Parv_boy is an unknown quantity at this point 
Solved Threads: 0
Parv_boy Parv_boy is offline Offline
Newbie Poster

Re: Finding Coefficients of a polynomial, roots are provided from command line

 
0
  #2
Sep 13th, 2008
Hi!

If two roots are provided a,b

then the equation will be :

x^2 - (a + b)x + (ab) = 0

If three roots are provided a,b,c

then the equation will be (not sure) :

x^3 - (a+b+c)x^2 + (ab+bc+ca)x - (abc) = 0
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 206
Reputation: grumpier has a spectacular aura about grumpier has a spectacular aura about 
Solved Threads: 31
grumpier grumpier is offline Offline
Posting Whiz in Training

Re: Finding Coefficients of a polynomial, roots are provided from command line

 
1
  #3
Sep 13th, 2008
1) First, represent a polynomial (of the form c_0 + c_1*x + c_2*x^2 + .... c_n*x^n) is represented by an array with elements (c_0, c_1, c_2, c_3, .... c_n).

2) Work out how to multiply two arbitrary polynomials together. ie. given a polynomial A (a_0, a_1, a_2, a_3, .... a_n) and a polynomial B (b_0, b_1, b_2, b_3, .... b_m) work out how to obtain a polynomial A*B = C = (c_0, c_1, c_2, c_3, .... c_(m+n)). Hint: The process to produce C from A and B is called convolution.

3) For the first root on the command line, create a polynomial X = (root, 1).

4) For all other roots on the command line;
a) create a polynomial Y = (root, 1)
b) obtain a polynomial Z = X*Y using the approach worked out in Step 2.
c) set X = Z

5) Voila!!!
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 3
Reputation: jits_aps90 is an unknown quantity at this point 
Solved Threads: 0
jits_aps90 jits_aps90 is offline Offline
Newbie Poster

Re: Finding Coefficients of a polynomial, roots are provided from command line

 
0
  #4
Sep 16th, 2008
ya thnks dear...
actually, thats a solution when you have known number of roots...
But i am taking some number random number of roots from command line....
thats why i am facing a problem in coding it....
bye tc
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 3
Reputation: jits_aps90 is an unknown quantity at this point 
Solved Threads: 0
jits_aps90 jits_aps90 is offline Offline
Newbie Poster

Re: Finding Coefficients of a polynomial, roots are provided from command line

 
0
  #5
Sep 16th, 2008
hi thanks a lot!
in fact i had just worked out the same problem with the same logic.
u r too good!
bye tc
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC