namespace week4Matrix
{
class Program
{
int[,] a;
int[,] b;
int[,] c;
static void Main(string[] args)
{
}
public void TransposeMatrix()
{
for (int i = 0; i < a.GetLength(0); i++)
{
for (int j = 0; j < a.GetLength(1); j++)
{
c[j, i] = a[i, j];
}
}
}
public void AddMatrix()
{
int i, j;
if (a.GetLength(0) == b.GetLength(0) && a.GetLength(1) == b.GetLength(1))
{
c = new int[a.GetLength(0), b.GetLength(1)];
for (i = 0; i < a.GetLength(0); i++)
{
for (j = 0; j < a.GetLength(0); j++)
{
c[i, j] = 0;
for (int k = 0; k < a.GetLength(0); k++)
{
c[i, j] = a[i, j] + b[i, j];
}
}
}
}
}
public void MultiplyMatrix()
{
if (a.GetLength(1) == b.GetLength(0))
{
c = new int[a.GetLength(0), b.GetLength(1)];
for (int i = 0; i < c.GetLength(0); i++)
{
for (int j = 0; j < c.GetLength(1); j++)
{
c[i, j] = 0;
for (int k = 0; k < a.GetLength(1); k++) // OR k<b.GetLength(0)
c[i, j] = c[i, j] + a[i, k] * b[k, j];
}
}
}
else
{
Console.WriteLine("\n Number of columns in Matrix1 is not equal to Number of rows in Matrix2.");
Console.WriteLine("\n Therefore Multiplication of Matrix1 with Matrix2 is not possible");
Environment.Exit(-1);
}
}
}
}
ok so this is what I have so far.. I want the program to start off asking the user what he/she wants to do;
1. Addition
2. Multiplication
3. Transpose
4. Determinant
and then according to the choice call one of the methods.
Also I couldn't find a way to find the determinant except for this;
http://msdn.microsoft.com/en-us/library/system.windows.media.matrix.determinant.aspx
the problem with this is that I dont know how to use it..
Thank you in advance.