1- Write a program that finds a given sparse matrix is a skew-symmetric matrix or not. The program should print true or false.
Don't take any input from the user, assign the sparse array in the program code.
A skew-symmetric matrix is a square matrix A whose transpose is also its negative; that is, it satisfies the equation A = -AT. If the entry in the i th row and j th column is aij, i.e. A = (aij) then the symmetric condition becomes aij = -aji.
2- Write a program that shifts the elements of each row of a sparse matrix array by n positions.
Example:
Input:
int[,] s = new int[,] {{6,6,8},{0,0,15},{0,3,22},{0,5,-15},{1,1,11}, {1,2,3}, {2,3,-6}, {4,0,91}, {5,2,28}};
15 0 0 22 0 -15
0 11 3 0 0 0
0 0 0 -6 0 0
0 0 0 0 0 0
91 0 0 0 0 0
0 0 28 0 0 0
Shift by 2 positions
Output:
0 -15 15 0 0 22
0 0 0 11 3 0
0 0 0 0 0 -6
0 0 0 0 0 0
0 0 91 0 0 0
0 0 0 0 28 0
VulpesPosted Nov 21, 2011, 10:46 AM
I don't see what difference it makes that the matrix is sparse as the code is just the same as for a 'dense' matrix. Sure, you could put in code to check that you're not moving a zero element into a place which already had a zero element but it hardly seems worth the effort.
Sam HobbsPosted Nov 20, 2011, 7:12 PM
Also, I don't understand the problem of shifting the "elements of each row of a sparse matrix array by n position". I don't understand how the result corresponds with the input. So I cannot help with that; I hope someone can. Unfortunately it is too late for Vulpes to get to this before Monday morning.
Your program says "Given Matrix is : " but I think it does not show the given matrix. Since the matrix is a typical dense matrix, I could help with that but I assume that does not help.
Taklaci GuvercinPosted Nov 20, 2011, 6:53 AM
static void Main(string[] args)
Console.WriteLine("Given Matrix is : ");
int[,] s = new int[,] { { 15, 0, 0, 22, 0, -15 }, { 0, 11, 3, 0, 0, 0 }, { 0, 0, 0, -6, 0, 0 }, { 0, 0, 0, 0, 0, 0 }, { 91,0, 0, 0, 0, 0 }, { 0, 0, 28, 0, 0, 0 } };
for(int a = 0; a <= 5; a++)
for (int b = 0; b <= 5; b++)
{
Console.Write(" ", +s[a, b]);
Console.WriteLine();
Console.WriteLine("Shiftted Matrix is : ");
int[,] x = new int[,] { { 0,-15,15,0, 0, 22 }, { 0, 0 , 0 ,11 ,3 , 0 }, { 0, 0 ,0, 0, 0,-6 }, { 0, 0, 0, 0, 0, 0 }, {0, 0,91,0 ,0 , 0 }, {0,0,0,0,28, 0 } };
for (int i = 0; i <= 5; i++)
for (int j = 0; j <= 5; j++)
{
Console.Write(" ", +s[i, j]);
Console.WriteLine();
}
{
}
Console.Read();Sam HobbsPosted Nov 17, 2011, 1:56 PM
Do you have specific questions? You are more likely to get help if you can be specific about what you need help with. What have you done to attempt to solve the problems? People that try to help others prefer to help someone with the problems for which the answer is not easily obtained but we prefer to obtain the answers themselves when they are relatively easy to find.