MATLAB: How to multiply the constants of a symbolic vector

errorMATLABsymprod

This is the code:
r = 2
p = sym('p', [1 r])
syms k
a =symprod(p(k),k,1,r)
And this is the result:
>> Untitled
r =
2
p =
[ p1, p2]
Error using sym/subsindex (line 737)
Invalid indexing or function definition. When defining a function, ensure that the arguments are symbolic variables and the
body of the function is a SYM expression. When indexing, the input must be numeric, logical, or ':'.
Error in sym/subsref (line 776)
R_tilde = builtin('subsref',L_tilde,Idx);
Error in Untitled (line 4)
a =symprod(p(k),k,1,r)
So i obtained that error which I cannot solve. The answer that im looking for is a = p1*p2*….*pr
Im using MATLAB 2015B.
Thank you for your help.

Best Answer

r = 2
p = sym('p', [1 r])
syms k
a =prod(p)