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

1 Ansicht (letzte 30 Tage)
Abdullah
Abdullah am 18 Okt. 2015
Kommentiert: Faisal Muhammad am 22 Okt. 2015

Antworten (2)

Walter Roberson
Walter Roberson am 19 Okt. 2015
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 am 18 Okt. 2015
Bearbeitet: Walter Roberson am 19 Okt. 2015
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 Kommentare
Faisal Muhammad
Faisal Muhammad am 22 Okt. 2015
Abdullah, Walter is right. Please check his solution.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by