Using functions relating polynomial

1 回表示 (過去 30 日間)
Vellan
Vellan 2019 年 12 月 9 日
コメント済み: Vellan 2019 年 12 月 13 日
Hi guys,
I would like to develop a function called poly_prod which determines the product of two polynomials. Let say P=[1 1 -7 -15] and Q=[3 -1 2], and when I use poly_prod(P,Q), the following answer is expected.
First Q(1)*P, which is [3 3 -21 -45]
Second Q(2)*P, which is [-1 -1 7 15]
Third Q(3)*P, which is [2 2 -14 -30]
Then it should be added like this:
[3 3 -21 -45 0 0] + [0 -1 -1 7 15] + [0 0 2 2 -14 -30]
and the final answer should show: [3 2 -20 -36 1 -30]
Thank you.
  2 件のコメント
Rik
Rik 2019 年 12 月 9 日
What have you tried so far? It sounds like a relatively easy function to implement with a loop. And it sounds like homework, so I've added the tag.
Vellan
Vellan 2019 年 12 月 9 日
編集済み: Rik 2019 年 12 月 9 日
Thanks for the reply.
This is what I have done so far
function ret=poly_prod(P1,P2)
n=poly_row(P1)
m=poly_row(P2)
a=size(n)
b=size(m)
ret=[];
for n=1:b(2)
ret=[ret P1*P2(n)]
end
end
The polyrow is a function that I created to make sure the polynomial is in a row vector.
I don't know how to carry on from this.

サインインしてコメントする。

採用された回答

Matt J
Matt J 2019 年 12 月 9 日
result = conv(P,Q)
  1 件のコメント
Vellan
Vellan 2019 年 12 月 13 日
Thanks Matt. It works.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFrequency Transformations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by