Consider an one dimensional convolution, and change the multiplication part (a*b) to power (a^b) and summation part (Sigma) to multiplication (Phi). How can I write a program for this using vectorization.

1 回表示 (過去 30 日間)
Shaik Ahmad
Shaik Ahmad 2016 年 10 月 5 日
コメント済み: Matt J 2016 年 10 月 12 日
Mathematically I want to implement a function. A and B are two integer arrays.
I have implemented the program using for loops (submitted below). How can I write a program for this using vectorization.
m=length(a);
n=length(b);
A=[a,zeros(1,n)];
B=[b,zeros(1,m)];
out=zeros(1,m+n-1);
for i=1:m+n-1
out(i)=1;
for j=1:m
if i-j+1>0
out(i)=out(i)*(A(j)^B(i-j+1));
end
end
end
Thank you.

回答 (1 件)

Matt J
Matt J 2016 年 10 月 5 日
編集済み: Matt J 2016 年 10 月 5 日
out= exp( conv(log(A),B) );
out=round(real(out));
  8 件のコメント
Shaik Ahmad
Shaik Ahmad 2016 年 10 月 7 日
編集済み: Shaik Ahmad 2016 年 10 月 12 日
Yes, you are correct. How can I overcome that problem. Any other solutions.
Matt J
Matt J 2016 年 10 月 12 日
Are they all non-negative integers?

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by