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

1 次查看(过去 30 天)

回答(2 个)

Walter Roberson
Walter Roberson 2015-10-19
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
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)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by