필터 지우기
필터 지우기

Multiplying two vectors together

조회 수: 1 (최근 30일)
Andrew
Andrew 2011년 10월 23일
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
Walter Roberson
Walter Roberson 2011년 10월 23일
Okay, but you have not asked a question.
How would you do it if you were doing the multiplication by hand?

댓글을 달려면 로그인하십시오.

답변 (2개)

Fangjun Jiang
Fangjun Jiang 2011년 10월 23일

Andrei Bobrov
Andrei Bobrov 2011년 10월 23일
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;

카테고리

Help CenterFile Exchange에서 Polynomials에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by