フィルターのクリア

How to obtain concatenated polynomials using MATLAB?

3 ビュー (過去 30 日間)
Amit Kumar
Amit Kumar 2019 年 2 月 7 日
回答済み: KSSV 2019 年 2 月 7 日
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 Center および File ExchangePolynomials についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by