Hello, I would like to convert this mathematical equation into MATLAB code.

2 ビュー (過去 30 日間)
hisham mohammed
hisham mohammed 2022 年 12 月 21 日
コメント済み: John D'Errico 2022 年 12 月 21 日
Hello, I would like to convert this mathematical equation into MATLAB code
  1 件のコメント
John D'Errico
John D'Errico 2022 年 12 月 21 日
You already got a valid answer. There is no reason to then post the same question a second time. I closed the other.

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

回答 (1 件)

Bora Eryilmaz
Bora Eryilmaz 2022 年 12 月 21 日
編集済み: Bora Eryilmaz 2022 年 12 月 21 日
x = rand(100,1);
N = numel(x);
num = (sum(x)/N)^2;
den = sum(abs(x.^2)) / N;
s = num / den
s = 0.7726
  1 件のコメント
Walter Roberson
Walter Roberson 2022 年 12 月 21 日
x_m = rand(100,1);
%Bora's version, valid only for reals
N = numel(x_m);
num = (sum(x_m)/N)^2;
den = sum(abs(x_m.^2)) / N;
s = num / den
s = 0.7135
%a more compact version valid only for reals
num2 = mean(x_m).^2;
den2 = mean(x_m.^2);
s2 = num2/den2
s2 = 0.7135
%analog for compact version but valid for complex as well
num3 = abs(mean(x_m)).^2;
den3 = mean(abs(x_m).^2);
s3 = num3 / den3
s3 = 0.7135
What you can get away with depends on whether there might be complex numbers involved.

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

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by