This project has moved and is read-only. For the latest updates, please go here.

RectangularMatrix multiplication fails

Dec 12, 2013 at 11:44 AM
Edited Dec 14, 2013 at 1:44 AM
Hi,

I'm learning Meta.Numerics lib esp for doing some matrices operations, so following is the code but it throws this exception:
Meta.Numerics.DimensionMismatchException: Operation is not valid due to the curr
ent state of the object.
at Meta.Numerics.Matrices.RectangularMatrix.op_Multiply(RectangularMatrix A,
RectangularMatrix B) in C:\Users\David\Documents\Code\Projects\Numerics\Core\Mat
rices\RectangularMatrix.cs:line 148
class Program
    {
        static void Main(string[] args)
        {
            double[,] a = new double[5, 2];
            a[0, 0] = 2; a[0, 1] = 3;
            a[1, 0] = 5; a[1, 1] = 4;
            a[2, 0] = 3; a[2, 1] = 1;
            a[3, 0] = 1; a[3, 1] = 2;
            a[4, 0] = 9; a[4, 1] = 6;

            double[,] b = new double[,] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 1, 8 }, { 3, 6 } };

            RectangularMatrix arm = new RectangularMatrix(a);
            RectangularMatrix brm = new RectangularMatrix(b);
            Console.WriteLine("arm rows: {0}, columns: {1}", arm.RowCount, arm.ColumnCount);
            Console.WriteLine("brm rows: {0}, columns: {1}", brm.RowCount, brm.ColumnCount);
            try
            {
                RectangularMatrix abrm = arm * brm;
                Console.WriteLine("arm * brm rows: {0}, columns: {1}", abrm.RowCount, abrm.ColumnCount);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            Console.Read();
        }
Dec 12, 2013 at 12:20 PM
Edited Dec 12, 2013 at 1:01 PM
You are multiplying two 5 x 2 matrices, which will of course not work. You would need to transpose either arm or brm before multiplying.

I also assume there is a typo in your code example? The multiplication should read:
RectangularMatrix abrm = arm * brm;
Right?
Dec 14, 2013 at 1:54 AM
Thank you cureos.

I have corrected the typo, which was for post only not in actual code, but when I used a transpose of one matrix, the multiplication worked!