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

Respuestas (2)

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 el 18 de Oct. de 2015
Editada: Walter Roberson el 19 de Oct. de 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 comentarios

thanks a lot Brother Faisal
This is incorrect.
Abdullah, Walter is right. Please check his solution.

Iniciar sesión para comentar.

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 18 de Oct. de 2015

Comentada:

el 22 de Oct. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by