MATLAB: Write the ‘+’, ‘-‘ signs in front of the polynomial coefficients

coefficientpolynomsigns

Hello
I have a coefficient vector of a polynomial and I want to introduce by a program the signs '+' and '-' in front of each coefficient.
ex: v = [2 -3 +4 -5]
Under the form: p = 2 * x. ^ 3 – 3 * x. ^ 2 + 4 * x – 5;
Who can help me thank you in advance.

Best Answer

Try this( Symbolic Toolbox is required for this code):

v = fliplr([2 -3 +4 -5]);
syms x;
fun(x)=sym(0);
for i=1:numel(v)
    fun(x)=fun(x)+v(i)*x^(i-1);
end
Related Question