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

1 vue (au cours des 30 derniers jours)
Abdullah
Abdullah le 18 Oct 2015
Commenté : Faisal Muhammad le 22 Oct 2015

Réponses (2)

Walter Roberson
Walter Roberson le 19 Oct 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 le 18 Oct 2015
Modifié(e) : Walter Roberson le 19 Oct 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 commentaires
Walter Roberson
Walter Roberson le 19 Oct 2015
This is incorrect.
Faisal Muhammad
Faisal Muhammad le 22 Oct 2015
Abdullah, Walter is right. Please check his solution.

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by