Problem reading persudo code

This is a discussion on Problem reading persudo code within the C++ Programming forums, part of the General Programming Boards category; Here is a part of the persudo code I read: Code: for k = 1 to N - 1 A(k+1:N, ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Have you read the FAQ?
    Place your best attempt and people will be glad to help you with fixing your errors.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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, 05: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, 09:33 AM
  4. Replies: 5
    Last Post: 12-03-2003, 04: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, 03:28 AM

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