Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: error using *, inner matrix dimensions must agree
Replies: 3   Last Post: Nov 6, 2016 5:24 AM

 Messages: [ Previous | Next ]
 Nasser Abbasi Posts: 6,677 Registered: 2/7/05
Re: error using *, inner matrix dimensions must agree
Posted: Sep 18, 2013 12:05 AM

On 9/17/2013 10:01 PM, nathan wrote:
> im trying to enter y = (sin(2*pi*t))*(sin(40*pi*t)) but it keep giving
>me the error using * inner matrix dimensions must agree. can you help fix this error
>

If t is a vector, which is most likely the case, then sin() will
generate a vector also. The little * between the 2 vectors is
matrix multiplication in Matlab.

To multiply 2 vectors or 2 matrices, the number of columns of
the left one must be same as number of rows of the right one.
These are called the inner dimensions of the 2 objects around
the "*" (inner since they both point towards the "*")

In your case, the number of columns of the left one vector
is not the same as the number of rows of the right one.

Let us assume your time 't' has 100 samples? or any value over 1.

So the left vector (which is now sin(2*pi*t)) will be
one row by 100 columns (since it is a row vector).

But the right vector (the result of sin(40*pi*t)) will
also have one row and 100 columns.

But "*" wants the right vector to have 100 rows to match the
number of columns of the left vector, or it want the left vector
to have one column to match the number of rows of the right vector,
since inner dimensions must match.

But 100 is not equal to one. So it complained.

One way to fix this is to use ".*" instead of "*" only
for the middle "*", like this

y = (sin(2*pi*t)) .* (sin(40*pi*t))

Now instead of matrix multiplication, element by element multiplication
is done. This should fix the problem.

--Nasser

Date Subject Author
9/17/13 nathan
9/18/13 Nasser Abbasi
10/11/16 Nguyen Hong Duc
11/6/16 ebu