Substitute a polynomial into another polynomial??

I want to subsitute x^2 (coefficients =[1 0 0]) into x^3+x+1 [1 0 1 1],
so I will obtain x^6+x^2+1 [1 0 0 0 1 0 1]
How can I do that?

 Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 12 Mai 2013
Modifié(e) : Andrei Bobrov le 13 Mai 2013
p1 = [1 0 1 1];
p2 = [1 0 0];
n2 = find(fliplr(p2(1:end-1)));
n1 = find(fliplr(p1(1:end-1)));
n = n1*n2;
pout(n) = 1;
out = fliplr([p1(end) pout]);
or without fliplr
n2 = find(p2(end-1:-1:1));
n1 = find(p1(end-1:-1:1));
n = n1*n2;
pout(n) = 1;
out = [pout(end:-1:1), p1(end)];

1 commentaire

Hi, I notice that it does not work for every equation such that
x^3 [1 0 0 0] ------> x^4 + x^2 + x + 1 [1 0 1 1 1]
It gives -------> x^12 + x^6 + x^4 + x^3 + x^2 + 1
Do you have a generalized method? At least could you explain the logic of your code?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Polynomials dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by