|
From: | Brian Blais |
Subject: | Re: Why is different ^ and .^? |
Date: | Mon, 23 May 2005 15:03:15 -0400 |
User-agent: | Mozilla Thunderbird 0.8 (X11/20040913) |
Javier Arantegui wrote:
Why the second option (^ instead of .^) doesn't work? Shouldn't be easier if you could use the same operator as when you are working with an scalar? I'd be happy if you could provide me an explanation that I could give to my students.
Octave does math using matrix algebra, not scalar algebra. Thus, if A and B are matrices, then
A*B requires that the number of columns of A be equal to the number of rows of B to do the proper matrix multiply. If you do:
A*A or A^2, then the matrix-math rule says that the matrix A must be square (a special case of the rule above).
Many times, however, you want to do an element-by-element multiply of two matrices. The proper way of doing this is:
A.*B , where A and B must be the same size (same number of elements). The same holds for element-by-element exponents:
A.^2Note, that the matrix addition/subtraction are the same as the element-by-element addition/subtraction, so you don't need a separate operator.
Brian Blais -- ----------------- address@hidden http://web.bryant.edu/~bblais ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------
[Prev in Thread] | Current Thread | [Next in Thread] |