Filter löschen
Filter löschen

Multiplying two vectors together

1 Ansicht (letzte 30 Tage)
Andrew
Andrew am 23 Okt. 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 Kommentar
Walter Roberson
Walter Roberson am 23 Okt. 2011
Okay, but you have not asked a question.
How would you do it if you were doing the multiplication by hand?

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Fangjun Jiang
Fangjun Jiang am 23 Okt. 2011

Andrei Bobrov
Andrei Bobrov am 23 Okt. 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;

Kategorien

Mehr zu Polynomials finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by