Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: error using *, inner matrix dimensions must agree
Replies: 1   Last Post: Sep 18, 2013 12:05 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Nasser Abbasi

Posts: 5,660
Registered: 2/7/05
Re: error using *, inner matrix dimensions must agree
Posted: Sep 18, 2013 12:05 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.