# Evaluate sums of powers of polynomial roots

%By Chukwunomso Agunwamba

%Evaluates sums of powers of polynomial roots

##

##This mathematical code is provided as is, for the end user to be able to use it

##and to edit it for educational purposes. However, any modified version must

##include my name as the original producer of the code.

##The name of the mfile code is getsumofpws. It has two input arguments.

##The first input is the power to which to raise the roots.

##The second input is the polynomial. (Note that if one has the roots already,

## one can simply directly raise them to the power and sum. But this code is

## for when one only has the coefficients of the polynomial.)

##

##So, symbolically speaking (not usage syntax),

##getsumofpws(k,Q) = sum((-V).^k), with Q(V) = 0 for each V. The polynomial

##coefficient vector is given in increasing powers here (not in reducing powers).

##

##Usage syntax examples:

##C = getsumofpws(3,[3 2 1])

##C = -10

##

##C = getsumofpws(4,[4 3 2 1])

##C = 18

## compare this to the result from: sum((-roots([1 2 3 4])).^4)