Matrix Help

This is a discussion on Matrix Help within the C++ Programming forums, part of the General Programming Boards category; A matrix is a twodimensional data structure. It is usually organized as a row of columns of numbers. Examples of ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    15

    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.

  2. #2
    Registered User
    Join Date
    Mar 2008
    Posts
    15
    My lecture notes don't help me. Any little info will greatly be appreciated

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    15

    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.

  4. #4
    Registered User
    Join Date
    Mar 2008
    Posts
    15

    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 |

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    15

    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?

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Have you started, gotten anywhere at all? Any attempt is better than no attempt. The instructions look pretty detailed . . . .
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Registered User
    Join Date
    Mar 2008
    Posts
    15
    Quote Originally Posted by dwks View Post
    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.

  8. #8
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Pick a language.
    Make an attempt.

    <<ugly merging brought to you in part by: Multiple Posting and Thread Bumping>>
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  9. #9
    Registered User
    Join Date
    Mar 2008
    Posts
    15
    Nah
    I tried
    spent 2 days on it
    I have something but it doesn't work.

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    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.

    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.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    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.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  13. #13
    Registered User
    Join Date
    Mar 2008
    Posts
    15
    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]);
    }

  14. #14
    Registered User
    Join Date
    Mar 2008
    Posts
    15

    Unhappy

    I'm so screwed this week.

  15. #15
    Registered User
    Join Date
    Mar 2008
    Posts
    15
    Can I be a mod?

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 01:30 PM
  2. Gauss-Jordan Matrix Inversion in C++
    By Max_Power82 in forum C++ Programming
    Replies: 3
    Last Post: 12-03-2006, 07:31 PM
  3. Matrix and vector operations on computers
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-11-2004, 06:36 AM
  4. Matrix Reloaded Questions (SPOILERS_
    By Xei in forum A Brief History of Cprogramming.com
    Replies: 73
    Last Post: 10-19-2003, 02:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21