HP Forums
HP-49G Vector-Matirx Multiplication - Printable Version

+- HP Forums (https://archived.hpcalc.org/museumforum)
+-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html)
+--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html)
+--- Thread: HP-49G Vector-Matirx Multiplication (/thread-87015.html)

HP-49G Vector-Matirx Multiplication - William - 02-08-2006

Can someone please tell me why my HP-49G will not multiply a vector [nx1] times a matrix [nxn], but it will multiply a matrix [nxn] times a vector [nx1]? Vector-matrix multiplication is a perfectly valid mathematical operation, but the HP-49G gives me an "Invalid Dimension" error. I know that I can overcome this error by placing the vector in the last row of an [nxn] matrix, but I perform this operation many times for my some of my engineering courses and this process becomes cumbersome, especially during an exam.

Re: HP-49G Vector-Matrix Multiplication - Marcus von Cube, Germany - 02-08-2006


you need a "horizontal" vector on the left side of a matrix. To create it, just enclose a vector in another pair of brackets.

2:[ [ 1 2 3 ] ]
1:[ [ 1 0 0 ]
[ 0 1 0 ]
[ 0 0 1 ] ]
This multiplies fine.


Edited: 8 Feb 2006, 11:01 a.m.

Re: HP-49G Vector-Matirx Multiplication - Namir - 02-08-2006

When you multiple a vector and a matrix you are really multiplying a row/column matrix with a matrix. Therefore the rule regarding the matrices' dimensions must be obayed.


Re: HP-49G Vector-Matirx Multiplication - Chris Dean - 02-08-2006

You can only multiply matrices A and B if the number columns of A is the same as the number of rows of B.

Consider C=AxB then if A is MxN and B is NxP then resultant matrix C is MxP.

Cij=sum(Aik*Bkj) where k = 1 to N

Re: HP-49G Vector-Matirx Multiplication - Karl Schneider - 02-08-2006

William --

As others explained previously, the result of matrix multiplication A*B includes the set of all dot products of the rows of A with the columns of B. The matrices must be dimensioned accoringly: the number of columns of A must equal the number of rows of B. A column vector is a matrix with only one column; a row vector is a matrix with only one row.

Also: In general, matrix multiplication is not commutative, even if both orders of multiplication are defined under the rules.

If one wants to left-multiply a column vector by a matrix, the column vector must usually be transposed as a row vector. The result will be dimensioned as a row vector.

There is a built-in function ATB on the HP-15C for that purpose. In Matlab, it would be A'*B.

A useful theorem: (A*B)T = BT*AT


-- KS

Re: HP-49G Vector-Matirx Multiplication - William - 02-09-2006

Thank you all for your input. I may not have made my problem clear in my previous message. So, I will try again. This is what I am doing.

[1 2 3] <sto> A (1 row x 3 columns)

[[1 2 3]
[1 2 3]
[1 2 3]] <sto> B (3 rows x 3 columns)

The number of columns in A i equal to the number of rows in B. I am defining these matrices via MTRW. The operation AxB should yield...[6 12 18]...however, my HP-49G says..."Invalid Dimension". The calculator will calculate BxA = [14 14 14]; THIS operation should give me an error message. Isn't this the opposite of what I should be getting? Do I have some obscure flag un-checked?

Thank you,

Re: HP-49G Vector-Matrix Multiplication - Karl Schneider - 02-10-2006

William --

You're in luck -- I also happen to have an HP-49G, so was able to try your example. (I should point out that in RPL, it's {data} 'A' STO, not {data} STO 'A'...)

I follow the example -- it looks to me like a row-vector A and a square matrix B. The vector entered with a single set of brackets on one line even looks like a row vector in the Matrix Editor.

But, when multiplying them with 'A' above 'B' in the stack, I get the same dimension error. Marcus von Cube's post has the fix: Make 'A' a true row vector by enclosing it within an extra set of brackets. ("TRAN" will also transpose a matrix or vector on the 49G.) I noticed that, for whatever reason, the transpose made no difference in the vector's layout in Matrix Editor.

[14 14 14]T is the product B*AT -- i.e., the matrix times the column vector.

I struggled to get my 48G to do what I wanted in this example, also.

How counterintuitive! This deepens my appreciation for the HP-15C and HP-42S, both of which I would trust far more than any RPL model to use on an important exam.

-- KS

Re: HP-49G Vector-Matrix Multiplication - Marcus von Cube, Germany - 02-10-2006

[ 1 2 3 ]
is a column vector,


[[ 1 2 3 ]]
is a row vector.

The strange thing is that matrix editor doesn't seem to know the difference. Or does he?

Function key F2 toggles the vector mode. I checked it on the 48S, 48G and 49G+, all three have this toggle. The 49G+ uses a single boldface pair of brackets in stack display to denote a row vector while the older calculators keep the double pair of brackets.

I assume the RPL designers on the 28C/S wanted the more common vector type (column vector) to have the simpler notation. The matrix editor came into play much later.