How to obtain concatenated polynomials using MATLAB?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Amit Kumar
el 7 de Feb. de 2019
Respondida: KSSV
el 7 de Feb. de 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?
0 comentarios
Respuesta aceptada
KSSV
el 7 de Feb. de 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
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Polynomials en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!