필터 지우기
필터 지우기

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 CenterFile Exchange에서 Polynomials에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by