Azzera filtri
Azzera filtri

Multiplying two vectors together

1 visualizzazione (ultimi 30 giorni)
Andrew
Andrew il 23 Ott 2011
I'm trying to write a function that takes 2 polynomials as inputs and multiplies them together. the two inputs have to be in vector form. 5x^2+7x+8 means you would type in [5 7 8]. i want the output to be in vector form.
  1 Commento
Walter Roberson
Walter Roberson il 23 Ott 2011
Okay, but you have not asked a question.
How would you do it if you were doing the multiplication by hand?

Accedi per commentare.

Risposte (2)

Fangjun Jiang
Fangjun Jiang il 23 Ott 2011

Andrei Bobrov
Andrei Bobrov il 23 Ott 2011
youfunction = @(p1,p2)conv(p1,p2)
or [ edit 10/24/2011 09:14 MSD ]
function out = yourfunction(p1,p2)
m = numel(p1);
n = numel(p2);
A = bsxfun(@minus,1:m+n-1,(0:n-1)');
A(A<1|A>m)=1;
out = p2*tril(triu(p1(A)),m-1);
more variant [ add 10/24/2011 11:41 MSD ]
function out = yourfunction(p1,p2)
m = numel(p1);
n = numel(p2);
A = zeros(n,m+n-1);
A(bsxfun(@plus,1:n:(n-1)*m,(0:n+1:(n^2-1))')) = ones(n,1)*p1;
out = p2*A;

Categorie

Scopri di più su Polynomials in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by