This project has moved. For the latest updates, please go here.

ColumnVectorA product with ColumnVectorB.transpose

Mar 7, 2013 at 8:50 AM
Edited Mar 7, 2013 at 11:28 AM
Dear All,

sorry I should have posted it in the issue tracker

I'm starting to use your library with VB in VS2008 with a 64bit Win7pro, since examples are quite a few I'll try to forward direct questions to your attention.
I need to make a product between a vectorA(M) and a vectorB(M) transposed, that shall result in an MxM matrix, I tried:
Dim PtsT()(), PtsR()() As Double
Dim PcvT, PcvR As ColumnVector
Dim PtPr As SquareMatrix
For i As Integer = 0 To UBound(PtsT)
  PcvT = New ColumnVector(PtsT(i))
  PcvR = New ColumnVector(PtsR(i))
  PtPr = PcvT * PcvR.Transpose
but there cannot be a format conversion due to my option strict
Errore 1 Option Strict On non consente conversioni implicite da 'Meta.Numerics.Matrices.RectangularMatrix' a 'Meta.Numerics.Matrices.SquareMatrix'.

Is there a mistake of mine or such product is not possible in your library?

Thanks in advance
Mar 8, 2013 at 5:30 AM
Edited Mar 8, 2013 at 5:31 AM
The short answer is that you just need to do an explict cast and it will all work out:
        Dim u As New ColumnVector(1, 2, 3)
        Dim v As New RowVector(4, 5, 6)
        Dim uv As SquareMatrix = CType(u * v, SquareMatrix)
The reason is that multiplying a column vector times a row vector doesn't always produce a square matrix. If the column vector is length 3, and the row vector is length 2, then the matrix produced is 3 X 2. You can see this in code by executing the following:
        Dim u As New ColumnVector(1, 2, 3)
        Dim v As New RowVector(4, 5)
        Dim uv As RectangularMatrix = u * v
        Console.WriteLine("{0} X {1}", uv.RowCount, uv.ColumnCount)
which will print out "3 X 2". In the .NET type system, the type returned by an operation can only depend on the types of its inputs, not by their specific content, so the most we can say about multiplying a column vector by a row vector is that it returns a rectangular matrix, but not necessarily always a square matrix. If the resulting matrix does happen to be square, you can always cast it to a square matrix and proceed from there. Thanks for asking!
Mar 8, 2013 at 11:27 AM
Thanks for your answer, I performed nice SVD matrices calculations with your library in just one or two line code but this simple one was making me wondering
so far I'm appreciating your library thank again