Asked by Passband Modulation
on 4 Oct 2012

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?

*No products are associated with this question.*

Answer by Walter Roberson
on 4 Oct 2012

Accepted answer

The MATLAB operator "*" is matrix multiplication. Element-by-element multiplication is ".*"

cos(3.6*n) .* sin(3.6*n)

Show 2 older comments

Jan Simon
on 4 Oct 2012

"n" is a vector, "cos(3.6 * n)" is a vector , "cos(3.6 * n) .* sin(3.6 * n)" is a vector, then "x .* x" is a vector also. Why do you expect a scalar? Do you want:

y = x * transpose(x)

Passband Modulation
on 4 Oct 2012

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
on 4 Oct 2012

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.

Related Content

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
## 2 Comments

## Daniel Shub (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/49872#comment_103056

do you want n to be

0:65119or0.65119?## Passband Modulation (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/49872#comment_103059

that is a summation, summing up from n=0 to n=65119. as a result it must be 0:65119.