How to obtain concatenated polynomials using MATLAB?

6 vues (au cours des 30 derniers jours)
Amit Kumar
Amit Kumar le 7 Fév 2019
Réponse apportée : KSSV le 7 Fév 2019
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?

Réponse acceptée

KSSV
KSSV le 7 Fév 2019
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

Plus de réponses (0)

Catégories

En savoir plus sur Polynomials dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by