Got Questions? Get Answers.
Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
help with matrix

Subject: help with matrix

From: david

Date: 28 Feb, 2012 16:50:11

Message: 1 of 6

Hello all,
If we have the following equation Y=G*Q with Y,G,Q are matrix
How to calculate the G matrix from this equation G=Y*inv(Q) or G=inv(Q)*Y ?
I have a problem with understanding the order in the multiplication expression, could you help me understanding this ?

Thanks in advance
Best regards

David

Subject: help with matrix

From: Mathew Thomas

Date: 28 Feb, 2012 17:59:10

Message: 2 of 6

The dimensions of the matrix will have to be the same.

for example:

Case I:

a = rand(5,5);
b = rand(5,10);
'INV' of a matrix can only be done on a square matrix.
a = inv(a);
multiply = a.*b;
This will work...
-----------------------------------------------------------------------------------------------
Case II:

a = rand(5,5);
b = rand(10,5);
'INV' of a matrix can only be done on a square matrix.
a = inv(a);
multiply = a.*b;

You will get:
Error using *
Inner matrix dimensions must agree.
----------------------------------------------------------------------------------------------------

Subject: help with matrix

From: Steven_Lord

Date: 28 Feb, 2012 18:04:41

Message: 3 of 6



"david " <david.sabine760@gmail.com> wrote in message
news:jij0k3$jku$1@newscl01ah.mathworks.com...
> Hello all, If we have the following equation Y=G*Q with Y,G,Q are
> matrix How to calculate the G matrix from this equation G=Y*inv(Q) or
> G=inv(Q)*Y ?

Don't use INV. Use \ or / instead. Execute these commands for more
information:

help mldivide % \
help mrdivide % /

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: help with matrix

From: Roger Stafford

Date: 29 Feb, 2012 00:45:13

Message: 4 of 6

"david" wrote in message <jij0k3$jku$1@newscl01ah.mathworks.com>...
> If we have the following equation Y=G*Q with Y,G,Q are matrix
> How to calculate the G matrix from this equation G=Y*inv(Q) or G=inv(Q)*Y ?
- - - - - - -
  In answer to your question, G=Y*inv(Q) would be the right way, not inv(Q)*Y. To remember which is correct think of multiplying both sides of the equation Y=G*Q on the right by inv(Q) giving you Y*inv(Q) = G*Q*inv(Q) = G*eye(n) = G.

  As Steve has indicated, it is more efficient to use matlab's right matrix division to find G: G = Y/Q rather than finding inv(Q), which involves extensive computation. (At least this is true if the number of rows in Y and G is less than the number of rows and columns in Q and the number of columns in Y and G.) You can use a similar memory device to that in the first paragraph to tell whether Y/Q or Q\Y is correct.

Roger Stafford
 

Subject: help with matrix

From: david

Date: 2 Mar, 2012 14:58:30

Message: 5 of 6

"Roger Stafford" wrote in message <jijsep$p7u$1@newscl01ah.mathworks.com>...
> "david" wrote in message <jij0k3$jku$1@newscl01ah.mathworks.com>...
> > If we have the following equation Y=G*Q with Y,G,Q are matrix
> > How to calculate the G matrix from this equation G=Y*inv(Q) or G=inv(Q)*Y ?
> - - - - - - -
> In answer to your question, G=Y*inv(Q) would be the right way, not inv(Q)*Y. To remember which is correct think of multiplying both sides of the equation Y=G*Q on the right by inv(Q) giving you Y*inv(Q) = G*Q*inv(Q) = G*eye(n) = G.
>
> As Steve has indicated, it is more efficient to use matlab's right matrix division to find G: G = Y/Q rather than finding inv(Q), which involves extensive computation. (At least this is true if the number of rows in Y and G is less than the number of rows and columns in Q and the number of columns in Y and G.) You can use a similar memory device to that in the first paragraph to tell whether Y/Q or Q\Y is correct.
>
> Roger Stafford
>

Thanks for your reply.
What about the case where all the matrix have the same dimension n*n ?

Best regards

Subject: help with matrix

From: Roger Stafford

Date: 2 Mar, 2012 20:57:12

Message: 6 of 6

"david" wrote in message <jiqn6m$chu$1@newscl01ah.mathworks.com>...
> What about the case where all the matrix have the same dimension n*n ?
- - - - - - - - - -
  On my machine when Y and Q are both 32 by 32, doing Y*inv(Q) is about 25% faster than Y/Q. The break-even point occurs with Y a size 18 by 32 with both methods taking about the same time. With Y a size 1 by 32, doing Y/Q is twice as fast as Y*inv(Q). This is about what I might have expected. Of course on a different machine with a newer matlab version the results may be different. You should experiment with it yourself.

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us