creating algorithm for specific computation

1 回表示 (過去 30 日間)
sermet 2018 年 9 月 19 日
コメント済み: Guillaume 2018 年 9 月 19 日
I need to perform below computation using algorithm approach.
t=100; % constant et=1:1:4; % the numbers of "et" are variable.
How can I create algorithm to perform above computation automatically with respect to the array number of et?


Guillaume 2018 年 9 月 19 日
If I understood correctly:
numerators = t - repmat(et(:), 1, numel(et)); %calculate t-et(1), t-et(2), etc.
numerators(logical(eye(size(numerators)))) = 1; %replace t-et by 1 on diagonal
numerators = prod(numerators);
denominators = et - et';
denominators(logical(eye(size(denominators)))) = 1;
denominators = prod(denominators);
result = sum(numerators ./ denominators);
However, the result of this is always going to be 1. So
result = 1;
may be simpler.
  2 件のコメント
sermet 2018 年 9 月 19 日
編集済み: sermet 2018 年 9 月 19 日
I got "Matrix dimensions must agree" error for denominators = et - et'; line
Guillaume 2018 年 9 月 19 日
That would be because you're using an ancient version of matlab (< R2016b). In older versions:
denominators = bsxfun(@minus, et, et');


その他の回答 (0 件)


Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by