フィルターのクリア

Multiplication implementation help?

1 回表示 (過去 30 日間)
Steve
Steve 2011 年 10 月 6 日
Hello Experts,
I need to write MATLAB code and to build a product like this:
for i from 1 to d, multiplication (x(i)-x(j)). x is a row vector of size d.
Here is what I did:
m = 0;
for i=1:d
for j=1:d
if i~=j
m = prod(x(i)-x(j));
end
end
end
But I am not sure if I am right...can you please help me with this?
  2 件のコメント
Fangjun Jiang
Fangjun Jiang 2011 年 10 月 6 日
format your code next time
Steve
Steve 2011 年 10 月 6 日
But am I right?

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

採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 10 月 6 日
You need to initialize m=1 and then do m=m*(x(i)-x(j)), or m=prod([m,x(i)-x(j)]). Use a test vector of x to verify the result.
  1 件のコメント
Steve
Steve 2011 年 10 月 6 日
Thank you very much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Code Analysis についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by