MATLAB: Distribution a syms variable with i loop over a vector

syms variable loop a vector

i need to Distribution a syms variable with i loop over a vector and make a polynomial summation to make it in this form
p(u) =2(1- u)^3*p0 + 2(1- 2u)*p1 + 2u*p2....
the equation is sum(r*p(i))
I already execute r which it an vector
r = [ -(u - 1)^3, 3*u*(u - 1)^2, -3*u^2*(u - 1), u^3]
and the code i use for the rest of equation not work
d=r
syms p
for i=0:k
p(u)=sum(d*p(i))
end
it show an error
Error using sym>checkindex (line 1545)
Index must be a positive integer or logical.
Error in sym>privformatscalar (line 1492)
checkindex(x);
Error in sym>privformat (line 1476)
s = privformatscalar(x);
Error in sym/subsref (line 685)
[inds{k},refs{k}] = privformat(inds{k});
Error in test1 (line 14)
p(u)=d*p(i)

Best Answer

p = [sym('p0'), sym('p', [1,k])]; %sym() starts them from 1 so need to prepend p0
pu = symfun( sum( r .* p), u);