0

I have a matrix which is 2 by 11 which I need to concatenate to a m by 11 matrix. Currently I have an event which triggers this operation. I am quite new to C# and haven't done some matrix manipulation so the answer may be very simple.

private double[,] A;

private void Window_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
        //variables xk,yk,zk ... assigned here
        double[,] a = { { xk, yk, zk, 1, 0, 0, 0, 0, xkxp, ykxp, zkxp }, { 0, 0, 0, 0, xk, yk, zk, 1, xkyp, ykyp, zkyp} };
        if (A == null)
        {
           //On the first event A will be null
            A = a;
        }
        else
        {
            //Concatenate A and a here
            a.CopyTo(A, A.Length);
        }
    }

Would it be easier if I broke variable "a" into two separate rows? What is the indexing that I need to use?

The A matrix needs to stay or become a double[,] for the operation that I apply to it. The operation doesn't need to happen till the matrix is 'complete' at the end of the program. I thought about just creating an array and then reshaping at the end but I'm not sure how to do this.

Cryptomnesia
  • 21
  • 1
  • 4
  • In case your are on a way to perform some serious algebra work, don't reinvent the wheel, use [this](http://mathnetnumerics.codeplex.com), for example. – galenus Oct 22 '13 at 11:53

1 Answers1

1

I think you would need to do this manually in this case. However, since you're adding empty rows at the end of the matrix, that shouldn't be difficult. If you declare your matrix as (example)

double[][] a = new[] { new double[7], new double[7]  };

you will even be able to address the rows individually.

I suggest you write (or use) a specific matrix class instead of using plain double arrays. Then you can add the required functionality to that class.

PMF
  • 14,535
  • 3
  • 23
  • 49
  • @PMF Thanks for this. I need to take this matrix and solve Ax=b as Cesar shows [here](http://stackoverflow.com/questions/8563124/c-sharp-algebra-linear-library) which is why I'm using the double arrays currently. I'll have a look into what you suggested. – Cryptomnesia Oct 22 '13 at 12:50