Thread: Nested Loop with add-on Equation..?? Seems Impossible!

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    32

    Question Nested Loop with add-on Equation..?? Seems Impossible!

    I'm able to do all the things required in my assignmen...except this problem.....

    I've the following equation (a very simple equation):
    Code:
    AOA = (ACC[j] + ACC[i])/2      (1st round of looping)
    In the first round of looping, ACC[j] are added to ACC[i] and find thier average...but in 2nd round of looping...
    Code:
    AOA = [(ACC[j] + ACC[i])/2 + (ACC[j] + ACC[i])/2]/2 (2nd round of looping)
    Next...in the 3rd round of looping....
    Code:
    AOA = [(ACC[j] + ACC[i])/2 + (ACC[j] + ACC[i])/2 + (ACC[j] + ACC[i])/2]/3      (3rd round of looping)
    These goes on and on until "n" round of looping......

    In order for u people to get better understanding of my intention, my codes are below:
    Code:
    i=0;
    for (i=0; i<Columns-1; i++){
    	for (j=0; j<Columns-1; j++){
    
    		if (Selected[i] == 1 && UnSelected[i] == 0){  //i:Selected   j:Candidate feature (unselected)
    			if (Selected[j] == 0 && UnSelected[j] == 1){  //[j], the ACC must be from unselected feature ==> "Selected[j] ==0"
    				AOA = (ACC[j] + ACC[i])/2;    // This is WRONG.....What should this be to make it flexible??
    				P_Plus_A[j] = 0.1 * P[j] + 0.9 * AOA;
    
    			}//End If
    		}//End If
    	}//End For
    }//End For	
    
    //After calculation, calculated lowest value are selected...
    //Next round of looping starts with add-on of equation
    So my question is: How to keep adding the equation on and on...??

    _____

  2. #2
    Registered User
    Join Date
    Dec 2002
    Posts
    56
    Just use the loop variables to multiplie and divide by. Factor out (ACC[j] + ACC[i]) and you'll get:

    (ACC[j] + ACC[i]) * [1/2 + 1/2] / 2; // second loop

    (ACC[j] + ACC[i]) * [1/2 + 1/2 + 1/2] / 3; // third loop

    Every loop iteration, you get (ACC[j] + ACC[i]) * 1/2 if you simplify the above equations. I'm not sure if that's what you are expecting, but that's what you're doing. If you want to keep a running total of the averages, you can just do something like:

    AOA += average;

    I'm not entirely sure what you're trying to accomplish

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    32
    (ACC[j] + ACC[i]) * [1/2 + 1/2] / 2; // second loop

    (ACC[j] + ACC[i]) * [1/2 + 1/2 + 1/2] / 3; // third loop
    How do you get that...??

    _____

  4. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    56
    Quote Originally Posted by AssistMe
    How do you get that...??

    _____
    Math

    (ACC[j] + ACC[i]) is a common term... Your equations simplify to (ACC[j] + ACC[i])/2 for every loop iteration. So, that's why I don't know if that's what you're trying to do or if you know exactly what you are doing..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual Studio Express / Windows SDK?
    By cyberfish in forum C++ Programming
    Replies: 23
    Last Post: 01-22-2009, 02:13 AM
  2. speeding up nested for loop
    By Unregistered in forum C++ Programming
    Replies: 11
    Last Post: 03-16-2002, 05:52 PM
  3. nested loop stuff
    By bob20 in forum C++ Programming
    Replies: 2
    Last Post: 12-14-2001, 12:24 PM
  4. Replies: 1
    Last Post: 11-19-2001, 04:45 PM
  5. Nested loop Problems
    By DramaKing in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2001, 11:33 AM