simple multiplication / summation using matlab

조회 수: 2 (최근 30일)
Passband  Modulation
Passband Modulation 2012년 10월 4일
i want to do some complicate calculations by matlab of following
n=0:65119;
x = cos(3.6*n)*sin(3.6*n);
y = x*x
it shows errors however, saying
Error in ==> ex3_1_2 at 3 x = cos(3.6*n)*sin(3.6*n);
what's happening?
  댓글 수: 2
Daniel Shub
Daniel Shub 2012년 10월 4일
do you want n to be 0:65119 or 0.65119?
Passband  Modulation
Passband Modulation 2012년 10월 4일
that is a summation, summing up from n=0 to n=65119. as a result it must be 0:65119.

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

채택된 답변

Walter Roberson
Walter Roberson 2012년 10월 4일
The MATLAB operator "*" is matrix multiplication. Element-by-element multiplication is ".*"
cos(3.6*n) .* sin(3.6*n)
  댓글 수: 5
Passband  Modulation
Passband Modulation 2012년 10월 4일
is not the result of that mathematical equation a scalar/single number?? is not it a scalar summation?? or i just made wrong code that is a vector???
Walter Roberson
Walter Roberson 2012년 10월 4일
You did not happen to show us the mathematical notation for what you are trying to do.
In MATLAB, 0:65119 is a row vector, 1 x 65120 in length. Matrix multiplication of two row vectors cannot be done: Matrix multiplication (mathematically) requires that the "inner dimensions" must be equal. Matrix multiplication is defined for (1 x 65120) * (65120 x 1) (giving a 1 x 1 result), and is defined for (65120 x 1) * (1 x 65120) (giving a 65120 x 65120 result), but it is not defined for (1 x 65120) * (1 x 65120)
It is mathematically possible to dot-product or cross-product vectors that have the same orientation; we cannot tell whether that is your intention.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by