Jonathan Lee
Jonathan Lee

Reputation: 155

How to create symbolic polynomial using coefficient vector and symbolic variable vector?

I have a coefficient column vector looking something like

x = [1 2 3]'

that aligns with the polynomial p(z) = x_0 + x_1*z + x_2*z^2 + ... + x_n-1*z^(n-1). My question is, how would one create a symbolic vector using MATLAB, something like

p = [1 z z^2]

so that when I take the matrix product

p*x

and print it I get a 1x1 "matrix" of the expression 1 + 2z + 3z^2?

Furthermore, how can I generalize the creation of p to extend for arbitrary powers z^3, z^4, ...?

Thanks!

Upvotes: 0

Views: 160

Answers (1)

Sardar Usama
Sardar Usama

Reputation: 19689

p = z.^(0:2);

In general:

p = z.^(0:n-1);

where n equals number of elements.

Upvotes: 1

Related Questions