Thread: Diagonal Matrix

  1. #1
    Registered User mlupo's Avatar
    Join Date
    Oct 2001
    Posts
    72

    Diagonal Matrix

    I'm reading and trying to work through some problems in my book in preparation for up and coming Data Structures finals. I came across this question in my book and I'm sorta scratching my head on it.
    Any dare to take a stab at it?

    Thanks in advance!
    Mike
    =======================
    The main diagonal of a square matrix consists of the entries for which the row and column indices are equal. A diagonal matrix is a square matrix in which all entries not on the main diagonal are zero.

    a) Describe a way to store a diagonal matrix without using space for entries that are zero.

    b) Give the corresponding index function.

    Here's what I deduce from my reading material.

    a)
    I’d implement a triangular table in a contiguous array by sliding each row out after the one above it. By placing each piece of data in the beginning of each row I store my data in a diagonal form.

    b) (i,j) corresponds to 1/2 i (i+1)+j

    ----------------------------------------------------
    Anyone care to sanity check me?


    Thanks in advance,
    Mike
    Last edited by mlupo; 12-04-2002 at 08:36 PM.
    NEVER PET YOUR DOG WHILE IT'S ON FIRE!

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    27
    I do similar operations in matlab when dealing with matrices. The simplest way to store a diagonal matrix is to just store the diagonal in a single dimension array. so every none zero element will be Aii so you just store those elements in A[i].

    and then if you have to you store the right hand side in another single dimension arraay so Rni is equal to R[i]


    And I guess for the function you could do something like this

    have them enter the index i and j
    Code:
    if(i == j)
      return A[i];
    else if(i = n)   // n being the width of the matrix
      return R[i];
    else 
      return 0;
    Last edited by samps005; 12-04-2002 at 10:05 PM.

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. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 05:57 PM
  3. Gauss-Jordan Matrix Inversion in C++
    By Max_Power82 in forum C++ Programming
    Replies: 3
    Last Post: 12-03-2006, 08:31 PM
  4. 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