How to obtain concatenated polynomials using MATLAB?

3 次查看(过去 30 天)
Hi
I am trying to obtain the coefficients of a polynomial (1+x)^i, where i varies from 1 to N.
The final result should concatenate the coefficients of all polynomials and produce resultant vector in powers of x.
Eg. (1+x)^2 = [(1 1) (1 2 1)] = [(x+1) (x^2 + 2x +1)]
I have tried writing the MATALB code as follows:
function y = eg10(N)
a = zeros(1,N)
y = zeros(1,N)
b = zeros(1,N)
p = [ 1 1]
syms x
q = poly2sym(p,x)
for i = 1:N
y(1,i) = q^i;
a(1,i) = coeffs(y(1,i))
b(1,i) = poly2sym(a(1,i),x)
c(1,i) = horzcat(b(1,i))
end
But I am getting error as follows:
The following error occurred converting from sym to double:
DOUBLE cannot convert the input expression into a double array.
Error in eg10 (line 9)
y(1,i) = q^i;
Can anyone kindly suggest any possible solution to this?

采纳的回答

KSSV
KSSV 2019-2-7
function y = eg10(N)
p = [ 1 1]
syms x
q = poly2sym(p,x)
y = cell(N,1) ;
a = cell(N,1) ;
b = cell(N,1) ;
c = cell(N,1) ;
for i = 1:N
y{i} = q^i;
a{i} = coeffs(y{i})
b{i} = poly2sym(a{i},x)
c{i} = horzcat(b{i})
end

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by