# Matrix Help

Printable View

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 03-05-2008
HelpmeMark
Matrix Help
A matrix is a twodimensional
data structure. It is usually organized as a row of columns
of numbers. Examples of matrices are:
A=[2 3 4
2 4 5
1 1 3 ] B=[5 6 2
2 5 3
1 6 7 ]
A and B are examples of 3 by 3 matrices. Each element of the matrix can be addressed by
the row, column indices, mathematically written as a(i,j) where i and j are the row and
column indices, respectively. In your program, you will use twodimensional
arrays of
floating point values to represent such matrices. In this assignment, you may assume that
the a matrix will be no larger than 5x5, but may also be smaller, with unequal
dimensions. You should use global variables to hold the dimensions of each matrix. So
the matrix A should be defined as:
double A[5][5];
and current dimension values (that may change as the user inputs new matrices):
int columnsA = 3; /* initial number of columns in A*/
int rowsA = 3; /* initial number of rows in A*/
Your program should be menu driven where the current matrix A is always displayed and
the user then selects matrix operations from the following menu:
| 1.0 0.0 0.0 |
A = | 0.0 1.0 0.0 |
| 0.0 0.0 1.0 |
(1)Set matrix A
(2)Add a matrix B (matrix addition)
(3)Multiply with a matrix B (matrix multiplication)
(4)Transpose matrix A
(5)Exit
Please enter your choice:
Your program should perform the following operations for the options:
(1) Enter matrix A
This function should allow the user to set the value of A by entering the dimensions and a
number for each element of the matrix.
For example, for a 2x3 matrix, it should prompt for values as follows:
Please enter the number of rows for A: 2
Please enter the number of columns for A: 3
Please enter A[0][0]: 1
Please enter A[0][1]: 2
Please enter A[0][2]: 1
Please enter A[1][0]: 2
Etc.
(2) Matrix Addition
Here, a second matrix B should be entered by the user. Then, the program should
compute the addition of the matrices A + B and assign the result back to matrix A so that
the result of the matrix addition is displayed before the next menu. (If you prefer, you
may store the result of the addition first in a local matrix C, and then copy C over to A).
Hint: Matrix addition is defined as follows:
C(i,j) = A(i,j) + B(i,j) for all values of i and j
(3) Matrix Multiplication
Again, this is very similar to option (2). Here, however, the matrix A should be
multiplied by matrix B by use of a matrix multiplication.
Hint: Each element in the result of a matrix multiplication A * B is computed as the sum
of the products of the row elements of A and the column elements of B.
(4) Transpose of the Matrix
Compute the transpose of matrix A.
Hint: The transpose of a matrix is obtained by swapping the row and column indices, i.e.
T(j, i) = A(i, j) for all i and j
(5) Exit
This option will terminate your program.
Implementation
To implement your program, you must use separate functions to perform the operations
required by the menu options. The function names should detail what the function does.
Please use the following function names: SetMatrixA( ), DisplayMatrixA( ),
AddMatrixBtoA( ) to perform the matrix addition, MultiplyMatrixBtoA( ) for matrix
multiplication, TransposeMatrixA(), and InvertMatrixA().
Define all matrices as global variables so that all functions have easy access to them.
There should be three matrices used in your program:
·Matrix A: used as the current matrix and the one on which all operations are
performed. The result of each operation should also be stored in matrix A for use in
the next operation. At the beginning of your program, this matrix should be initialized
to a 3x3 identity matrix (as shown at the beginning).
·Matrix B: used as the operand matrix. That is, when performing the addition,
multiplication, matrix A should be the first, and matrix B should be the second
operand. This should be consistent throughout the program.
·Matrix C: used as a temporary matrix. You may temporarily store the result of a
matrix operation in C. However, before returning to displaying the menu options,
matrix C should be copied over into A so that the result can be used for further
operations.
Script file
To demonstrate that your program works correctly, perform the following steps and
submit them as your script file:
1.Set matrix A to the following: A=[2 1 4 5
1 −1 −2 3
0 −3 3 −2 ]
2.Add the following matrix B to A: B=[2 −3 −5 −1
2 3 2 6
1 3 −3 1 ]
3.Multiply the resulting matrix with the following: B=[0 0 1
3 1 2
4 −3 −2
1 0 1 ]
4.Transpose matrix A.
5.Exit the program.
• 03-05-2008
HelpmeMark
My lecture notes don't help me. Any little info will greatly be appreciated
• 03-05-2008
HelpmeMark
Matrix Help
I am confused. Any little help will be appreciated ;) My notes don't help much.

A matrix is a twodimensional
data structure. It is usually organized as a row of columns
of numbers. Examples of matrices are:
A=[2 3 4
2 4 5
1 1 3 ] B=[5 6 2
2 5 3
1 6 7 ]
A and B are examples of 3 by 3 matrices. Each element of the matrix can be addressed by
the row, column indices, mathematically written as a(i,j) where i and j are the row and
column indices, respectively. In your program, you will use twodimensional
arrays of
floating point values to represent such matrices. In this assignment, you may assume that
the a matrix will be no larger than 5x5, but may also be smaller, with unequal
dimensions. You should use global variables to hold the dimensions of each matrix. So
the matrix A should be defined as:
double A[5][5];
and current dimension values (that may change as the user inputs new matrices):
int columnsA = 3; /* initial number of columns in A*/
int rowsA = 3; /* initial number of rows in A*/
Your program should be menu driven where the current matrix A is always displayed and
the user then selects matrix operations from the following menu:
| 1.0 0.0 0.0 |
A = | 0.0 1.0 0.0 |
| 0.0 0.0 1.0 |
(1)Set matrix A
(2)Add a matrix B (matrix addition)
(3)Multiply with a matrix B (matrix multiplication)
(4)Transpose matrix A
(5)Exit
Please enter your choice:
Your program should perform the following operations for the options:
(1) Enter matrix A
This function should allow the user to set the value of A by entering the dimensions and a
number for each element of the matrix.
For example, for a 2x3 matrix, it should prompt for values as follows:
Please enter the number of rows for A: 2
Please enter the number of columns for A: 3
Please enter A[0][0]: 1
Please enter A[0][1]: 2
Please enter A[0][2]: 1
Please enter A[1][0]: 2
Etc.
(2) Matrix Addition
Here, a second matrix B should be entered by the user. Then, the program should
compute the addition of the matrices A + B and assign the result back to matrix A so that
the result of the matrix addition is displayed before the next menu. (If you prefer, you
may store the result of the addition first in a local matrix C, and then copy C over to A).
Hint: Matrix addition is defined as follows:
C(i,j) = A(i,j) + B(i,j) for all values of i and j
(3) Matrix Multiplication
Again, this is very similar to option (2). Here, however, the matrix A should be
multiplied by matrix B by use of a matrix multiplication.
Hint: Each element in the result of a matrix multiplication A * B is computed as the sum
of the products of the row elements of A and the column elements of B.
(4) Transpose of the Matrix
Compute the transpose of matrix A.
Hint: The transpose of a matrix is obtained by swapping the row and column indices, i.e.
T(j, i) = A(i, j) for all i and j
(5) Exit
This option will terminate your program.
Implementation
To implement your program, you must use separate functions to perform the operations
required by the menu options. The function names should detail what the function does.
Please use the following function names: SetMatrixA( ), DisplayMatrixA( ),
AddMatrixBtoA( ) to perform the matrix addition, MultiplyMatrixBtoA( ) for matrix
multiplication, TransposeMatrixA(), and InvertMatrixA().
Define all matrices as global variables so that all functions have easy access to them.
There should be three matrices used in your program:
·Matrix A: used as the current matrix and the one on which all operations are
performed. The result of each operation should also be stored in matrix A for use in
the next operation. At the beginning of your program, this matrix should be initialized
to a 3x3 identity matrix (as shown at the beginning).
·Matrix B: used as the operand matrix. That is, when performing the addition,
multiplication, matrix A should be the first, and matrix B should be the second
operand. This should be consistent throughout the program.
·Matrix C: used as a temporary matrix. You may temporarily store the result of a
matrix operation in C. However, before returning to displaying the menu options,
matrix C should be copied over into A so that the result can be used for further
operations.
Script file
To demonstrate that your program works correctly, perform the following steps and
submit them as your script file:
1.Set matrix A to the following: A=[2 1 4 5
1 −1 −2 3
0 −3 3 −2 ]
2.Add the following matrix B to A: B=[2 −3 −5 −1
2 3 2 6
1 3 −3 1 ]
3.Multiply the resulting matrix with the following: B=[0 0 1
3 1 2
4 −3 −2
1 0 1 ]
4.Transpose matrix A.
5.Exit the program.
• 03-05-2008
HelpmeMark
Matrix
matrix A should be defined as:
double A[5][5];
and current dimension values (that may change as the user inputs new matrices):
int columnsA = 3; /* initial number of columns in A*/
int rowsA = 3; /* initial number of rows in A*/
Your program should be menu driven where the current matrix A is always displayed and
the user then selects matrix operations from the following menu:
| 1.0 0.0 0.0 |
A = | 0.0 1.0 0.0 |
| 0.0 0.0 1.0 |
• 03-05-2008
HelpmeMark
Matrix
Guess posting the entire thing didn't work, so right now i have
#include <stdio.h>

int i;
int j;
int select;
double A[5][5];
double B[5][5];
double C[5][5];
int columnsA = 3;
int rowsA = 3;

I want to display a 3x3 matix (1,0,0), (0,1,0), (0,0,1), but have no clue how.

Any suggestions?
• 03-05-2008
dwks
Have you started, gotten anywhere at all? Any attempt is better than no attempt. The instructions look pretty detailed . . . .
• 03-05-2008
HelpmeMark
Quote:

Originally Posted by dwks
Have you started, gotten anywhere at all? Any attempt is better than no attempt. The instructions look pretty detailed . . . .

#include <stdio.h>

int i;
int j;
int select;
double A[5][5];
double B[5][5];
double C[5][5];
int columnsA = 3;
int rowsA = 3;

now I want to display a 3x3 matrix, but have no clue how.
• 03-05-2008
Dave_Sinkula
Pick a language.
Make an attempt.

<<ugly merging brought to you in part by: Multiple Posting and Thread Bumping>>
• 03-05-2008
HelpmeMark
Nah
I tried
spent 2 days on it
I have something but it doesn't work.
• 03-05-2008
dwks
You have to put code inside code tags like this: [code] code goes here [/code]
Don't start new threads about the same topic. You can post in your other threads after you start them. Too late now -- perhaps a moderator can merge the threads.

Quote:

I want to display a 3x3 matix (1,0,0), (0,1,0), (0,0,1), but have no clue how.

Any suggestions?
Yes -- read up on for loops.
• 03-05-2008
matsp
And posting many copies of the same subject is a good way of upsetting the moderators, not a good way to get an answer.

Post your code so far, whatever it is, and we can help you get the next step done - but if you don't try yourself, you will not learn, and that's what we want you to do - not just learn how to ask someone else to do it for you - that's the management course, not the programming course ;-).

--
Mats
• 03-05-2008
dwks
Well, post it here. (In code tags, like I mentioned in the other thread.) That's what we do -- we help people with their code that doesn't work. We don't give them code that does work. :) It's the Homework policy.
• 03-05-2008
HelpmeMark
Code:

```int M[3][3] = {{1, 0,0}, {0, 1,0}, {0, 0,1}}; int i, j; for(i=0; i<3; i++) { for(j=0; j<3; j++) { printf(“&#37;d ”, M[i][j]); }```
• 03-05-2008
HelpmeMark
:( I'm so screwed this week.
• 03-05-2008
HelpmeMark
Can I be a mod?
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last