Please need help!! How to write this equation in terms of code?

回答 (2 件)

Walter Roberson
Walter Roberson 2015 年 10 月 19 日

1 投票

x = 1 : L;
px = arrayfun(@p, 1:L);
ex = 1/L * sum(px .* x) / sum(px);
If p is vectorized then you can use
x = 1 : L;
px = p(x);
ex = 1/L * sum(px .* x) / sum(px);
Faisal Muhammad
Faisal Muhammad 2015 年 10 月 18 日
編集済み: Walter Roberson 2015 年 10 月 19 日

0 投票

p(x)=1+x^2 % some function
for x=1:L
ex=1/L*((p(x)*x)/(p(x))
end
By the way the function can be reduced by canceling p(x)

3 件のコメント

Abdullah
Abdullah 2015 年 10 月 18 日
thanks a lot Brother Faisal
Walter Roberson
Walter Roberson 2015 年 10 月 19 日
This is incorrect.
Faisal Muhammad
Faisal Muhammad 2015 年 10 月 22 日
Abdullah, Walter is right. Please check his solution.

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

カテゴリ

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

製品

質問済み:

2015 年 10 月 18 日

コメント済み:

2015 年 10 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by