필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Abdullah
Abdullah 2015년 10월 18일
댓글: Faisal Muhammad 2015년 10월 22일

답변 (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)
  댓글 수: 3
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.

댓글을 달려면 로그인하십시오.

카테고리

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