Borrar filtros
Borrar filtros

Multiplying two vectors together

1 visualización (últimos 30 días)
Andrew
Andrew el 23 de Oct. de 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 comentario
Walter Roberson
Walter Roberson el 23 de Oct. de 2011
Okay, but you have not asked a question.
How would you do it if you were doing the multiplication by hand?

Iniciar sesión para comentar.

Respuestas (2)

Fangjun Jiang
Fangjun Jiang el 23 de Oct. de 2011

Andrei Bobrov
Andrei Bobrov el 23 de Oct. de 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;

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!

Translated by