Explanation of this statement

조회 수: 1 (최근 30일)
Ashutosh Shukla
Ashutosh Shukla 2014년 6월 30일
댓글: dpb 2014년 7월 1일
for i=1:N
yd(i) = sum(w(i)' .* x(i));
end
Can anyone explain the above statement to me?? I can't understand the use of sum as acc. to me w(i) and x(i) are just numbers and not whole vector. So what's the sum for. Don't doubt the code. It is correct. Just need an explanation.

답변 (2개)

dpb
dpb 2014년 6월 30일
Did you just look and see??? But, yes, you're evaluation is correct of the code as written--now whether that's what was intended is another question.
The above loop could be rewritten as
yd=w' .* x;
Try
all(yd)==all(w' .* x)
to prove it.
  댓글 수: 6
Ashutosh Shukla
Ashutosh Shukla 2014년 7월 1일
no complex numbers in calculation....
simple float(decimal) numbers...
dpb
dpb 2014년 7월 1일
no complex numbers in calculation....
Which I presumed was likely the case but just pointing out there is a difference if w were to be complex.

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


Robert Cumming
Robert Cumming 2014년 6월 30일
Looking at the code, unless sum is an overloaded function that does something other than the standard inbuild sum - it looks redundant.
To check what sum is - type:
which sum
To check its not doing anything - remove it and run the code again!
  댓글 수: 4
Ashutosh Shukla
Ashutosh Shukla 2014년 7월 1일
Also what is meant by w(i)'. how is it transposing single element??
dpb
dpb 2014년 7월 1일
That's why I brought up the complex number issue; the ' is the complex transpose which has no net effect if the values are real but does if they're not. Newbies often mistakenly use it when the non-complex transpose operator .' is intended instead, which is the case I presumed happened here.
See
doc punct
for details.
As noted, if it's written as a loop on an individual element for a real value it has no effect, just as the sum of a single value is simply the value.

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

카테고리

Help CenterFile Exchange에서 Financial Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by