How to create symbolic polynomials from a coefficient vector and symbolic vector?

3 次查看(过去 30 天)
Hello,
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, 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, ...?

采纳的回答

John D'Errico
John D'Errico 2018-9-30

As Walter shows, you can do it using provided tools easily enough. Just to understand how things work, you can also do it directly.

x = [1 2 3]';
syms z
p = z.^(0:(numel(x)-1));
polynom = p*x
polynom =
3*z^2 + 2*z + 1

Note that the symbolic toolbox has chosen to reorder the terms.

  2 个评论
Jonathan Lee
Jonathan Lee 2018-9-30
Do you know of any way to maintain the floating-point-ness of the coefficients? (i.e. 0.5124243523423 instead of 1395801/12985102)
Whenever I use Walter's or your solution, it always converts x into a symbolic array.
John D'Errico
John D'Errico 2018-9-30
编辑:John D'Errico 2018-9-30
You never said that was important, but you said you WANTED a symbolic result. syms converts floating point numbers into rational versions of those same numbers. That way, syms maintains super high precision, rather than using floating point arithmetic.
To convert those rational forms back into floating point numbers, just use vpa on the result.

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2018-9-30
poly2sym(fliplr(x.'), z)

类别

Help CenterFile Exchange 中查找有关 Number Theory 的更多信息

产品


版本

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by