Thread: Problem reading persudo code

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    25

    Problem reading persudo code

    Here is a part of the persudo code I read:

    Code:
    for k = 1 to N - 1
    
     A(k+1:N, k+1:N) = A(k+1:N, k+1:N) - A(k+1:N, k)*A(k, k+1:N)
    
    endfor
    My question is, what's mean by the notation k+1:N ?
    Also, can anyway please translate the persudo code above into real C++ code ?

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    From a google search on part of the formula, I think that A is a matrix, and A(m_1:m_2, n_1:n_2) is the submatrix with first coordinate running from m_1 to m_2 and second coordinate running from n_1 to n_2. This is consistent with the fact that when you multiply two matrices B*C, the number of columns of B must equal the number of rows of C, and the number of rows and columns of the product is equal to the number of rows of B and the number of columns of C, resp. So both sides of your equation are square matrices with N-(k+1)+1 rows and columns.

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    25
    You are right. This is really a part of matrix calculation.

    Then can I read the code as follows:

    Code:
    for k = 1 to N - 1
    
     A(k+1, k+1) = A(k+1, k+1) - A(k+1, k)*A(k, k+1)
    
    endfor

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    No, you can't drop the N like that. The formula in the loop depends on N. Also I should have mentioned that in the formula, k by itself is equivalent to k:k (they're just abbreviating), so the full version of the formula is

    A(k+1:N, k+1:N) = A(k+1:N, k+1:N) - A(k+1:N, k:k)*A(k:k, k+1:N)

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    25
    Anyway, does anyone know how to translate this piece of persudo code into real code that can run in C++.

    Thx

  6. #6
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Have you read the FAQ?
    Place your best attempt and people will be glad to help you with fixing your errors.
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with game code.
    By ajdspud in forum C++ Programming
    Replies: 5
    Last Post: 02-14-2006, 06:39 PM
  2. Replies: 6
    Last Post: 05-12-2005, 03:39 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Replies: 5
    Last Post: 12-03-2003, 05:47 PM
  5. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM