Multiplying two vectors together
조회 수: 3 (최근 30일)
이전 댓글 표시
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
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개)
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;
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Polynomials에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!