[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2235
  • Last Modified:

Expand (x-1)(x-2)...(x-n)

The solution to a problem is  P(x) = (x-1)(x-2)...(x-n)  (for some integer n).

However, I want to expand this polynomial, so as to find the coefficient of the ith power.

It's quite clear that:  a_n=1,  and  a_0=n!(-1)^n, but I've yet to figure a pattern for the others...

How would I approach this?


Thanks
0
InteractiveMind
Asked:
InteractiveMind
5 Solutions
 
anas_aliraqiCommented:
you can use Pascal's triangle to find any cof.
see this link
http://en.wikipedia.org/wiki/Pascal's_triangle
0
 
TalmashCommented:
a_1 = sigma ( -i ) for i=1..n  {or -(n+1)*n/2 }
a_n-1 = sigma ( PI {-i} for i=1..j-1 X PI {-i} for i=j+1..n ) for j=1..n
   you need a script/algo to calculate this even for a_n-1

a_n-k = sigma (choose subset k out of n) PI (k elements)

you need some functions:
1. subset_k_n (input n input k input start input prev_subset output next_subset output last)
2. PI_subset (input subset_array output subset_product)
3. SIGMA
  3.1 calls subset_k_n with start=1
  3.2 subset_k_n return with the 1st subset (1..k) = prev_subset
  3.3 calls PI_subset with (1..k)
  3.4 PI_subset return with k(k+1)/2
  3.5 SIGMA set this value as a_n-k
  3.6 call subset_k_n with prev_subset
  3.7 call PI_subset with the new subset
  3.8 add a_n-k the returned value from PI_subset
  3.9 goto 3.6 until subset_k_n->stop = 1

tal



0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
TalmashCommented:
wow! didn't knew about these stirling triangles!
anyway, no equation compute them stright forward.
0
 
Infinity08Commented:
I see ozo posted already, but I found this myself :

        a(n,n)   = 1

and for j = 1..n :

        a(n,n-j) = Sum(i=j..n) [ a(i-1,i-j) * (-i) ]

where a(x,y) is the y-th coëfficient for the x-th order polynomial.



Or, worked out :

a(0,0) = 1
    => 1 = 1

a(1,1) = 1
a(1,0) = Sum(i=1..1) [ a(i-1,i-1) * (-i) ] = -1
    => (x - 1) = x - 1

a(2,2) = 1
a(2,1) = Sum(i=1..2) [ a(i-1,i-1) * (-i) ] = (-1) + (-2) = -3
a(2,0) = Sum(i=2..2) [ a(i-1,i-2) * (-i) ] = 2
    => (x - 1)(x - 2) = x^2 - 3x + 2

a(3,3) = 1
a(3,2) = Sum(i=1..3) [ a(i-1,i-1) * (-i) ] = (-1) + (-2) + (-3) = -6
a(3,1) = Sum(i=2..3) [ a(i-1,i-2) * (-i) ] = 2 + 9 = 11
a(3,0) = Sum(i=3..3) [ a(i-1,i-3) * (-i) ] = -6
    => (x - 1)(x - 2)(x - 3) = x^3 - 6x^2 + 11x - 6

a(4,4) = 1
a(4,3) = Sum(i=1..4) [ a(i-1,i-1) * (-i) ] = (-1) + (-2) + (-3) + (-4) = -10
a(4,2) = Sum(i=2..4) [ a(i-1,i-2) * (-i) ] = 2 + 9 + 24 = 35
a(4,1) = Sum(i=3..4) [ a(i-1,i-3) * (-i) ] = (-6) + (-44) = -50
a(4,0) = Sum(i=4..4) [ a(i-1,i-4) * (-i) ] = 24
    => (x - 1)(x - 2)(x - 3)(x - 4) = x^4 - 10x^3 + 35x^2 - 50x + 24


etc.
0
 
ozoCommented:
#!/usr/bin/perl
$s[0][0]=1;
for$n( 0..20 ){
    print $s[$n+1][$_] = $s[$n][$_-1]-$n*$s[$n][$_],"x^",$_-1," " for reverse 1..$n+1;
    print "\n";
}
0
 
InteractiveMindAuthor Commented:
Wow
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now