MATLAB: What is the right way to put a polynomial into a function

functionpolynomial

I've tried 2 different lines within my code with variations of both, but nothing seems to be working. Any help would be appreciated.
The polynomial to be called is:
c0 +c(1)x1 +c(2)x2+...+c(N)xN
and below are my 2 attempts:
function p = poly_val(c0,c,x)
p = sum([c0 c] .* (x.^[0:length(c)]));
or
p = (c0 + polyval(c*(x.^c)));

Best Answer

"the polynomial ... is: c(0) +c(1)x^1 +c(2)x^2+...+c(N)x*N"
y=polyval(fliplr(c),x);
Better would be to define your coefficient array in obverse order as returned by supplied polyfit and used by polyval functions--then you have no need to write a separate function at all...see <polyfit>