summation divided by summation

Hey, the beautiful pupil of the world. I'm trying to implant the formula below to MATLAB. I wrote the denominator and the numerator in different 'for' loops but it doesn't work like that. then, I tried to use special sum code but it didn't work either. so, could you help me to solve this problem?
here is the code I used;
a=2;
l=2;
d1= (sum(l,l,0,l))*(r1.^a)./(sum(r1.^a,l,0,l));
d2= (sum(l,l,0,l))*(r2.^a)./(sum(r2.^a,l,0,l));
thanks in advance.

9 件のコメント

KSSV
KSSV 2017 年 11 月 28 日
Show us your code......we will edit it to the present one.
Onur Demir
Onur Demir 2017 年 11 月 28 日
here you are, sir.
per isakson
per isakson 2017 年 11 月 28 日
>> sum(l,l,0,l)
Error using sum
Trailing string input must be 'double', 'native', 'default', 'omitnan' or 'includenan'.
Read about the function sum in the documentation.
Walter Roberson
Walter Roberson 2017 年 11 月 28 日
What is your sum ? It does not appear to be the MATLAB sum function. It is confusing for the people reading the code when you use a name so similar to the standard MATLAB name.
Is r1 a vector or an array?
What is the part that looks like (l) ? Is it floor(l) or just brackets? Is that exp(l) or l^l at the beginning?
Onur Demir
Onur Demir 2017 年 11 月 28 日
Dear Walter, r1 and r2 are arrays. the thing is d1 and d2 are the last constants i need to calculate. others I've already found. so you can assume that r1 and r2 are constant values.
about the l, it is writing in the formula.
KSSV
KSSV 2017 年 11 月 28 日
How about l?
Onur Demir
Onur Demir 2017 年 11 月 28 日
it is supposed to be division. but it must be ./ thanks for showing me.
Jan
Jan 2017 年 11 月 28 日
@Onur: Did you consider the advice concerning "sum"? sum() is a built-in function, but calling it like sum(l,l,0,l) is not valid. If your "sum" is a user-defined function, use a different name, because shadowing important built-in functions is not an error, but very confusing.
Onur Demir
Onur Demir 2017 年 11 月 28 日
Everyone, I'm really appreciated that you helped me. I finally find my mistakes and solve them. Now I have another problem. If you want to help me, please check this page; https://www.mathworks.com/matlabcentral/answers/369732-implementation-of-the-cross-correlation

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

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 11 月 28 日

0 投票

Change your / to ./
And you should probably have about 30 or 40 lines of comments explaining in detail why you feel it is necessary to name your variable or custom function sum in conflict with the standard MATLAB function sum()

1 件のコメント

Onur Demir
Onur Demir 2017 年 11 月 28 日
編集済み: per isakson 2017 年 11 月 29 日
Walter, I'm really appreciated that you helped me. I finally find my mistakes and solve them. Now I have another problem. If you want to help me, please check this page; https://www.mathworks.com/matlabcentral/answers/369732-implementation-of-the-cross-correlation

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

カテゴリ

ヘルプ センター および File ExchangeEntering Commands についてさらに検索

タグ

質問済み:

2017 年 11 月 28 日

編集済み:

2017 年 11 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by