Welcome! Log In Create A New Profile

Advanced

Assignment 5 - Question 3

Posted by murfinke 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Assignment 5 - Question 3
July 04, 2007 01:24PM
I have implemented Question 2 and it works well but I a can't see what I am doing wrong on Q3. I have read pages 478 - 479 and I understand how the process works ( Or so I thought). But when it comes to programming it I get ridiculous results that I can't explain. The more iterations the greater the error. I have used Eq.(8.15) and Eq.(8.16). I am clearly missing something. Any ideas?


void calculateAverages()
{
     for(int i = 1; i < 4; i++)
         for(int j = 1; j < 5; j++)
              Arr[j] = (Arr[0][j] + Arr[4][j] + Arr[0] + Arr[5])/4.0;
}

void copyArr2Fixed()
{     
     for(int i = 0; i < 5; i++) // Assign Arr to the Fixed values K
                 for(int j = 0; j < 6; j++)      
                         Fixed[j] = Arr[j];
}

int calculateADI()
{
      double p = 1; 
      double test;            
      int iter = 0;
      
      calculateAverages();
                        
      do {
         test = Arr[1][1];         
         copyArr2Fixed();
          
         for(int i = 1; i < 4; i++)
                 for(int j = 1; j < 5; j++)
                     Arr[j] = Fixed[j] + p*(Arr[j-1]-(2*Arr[j])+ Arr[j+1])
                                             + p*(Fixed[i-1][j]-(2*Fixed[j])+ Fixed[i+1][j]);                                    
       iter++;
       copyArr2Fixed();     
                 
       for(int j = 1; j < 5; j++)
                 for(int i = 1; i < 4; i++)
                              
                      Arr[j] = Fixed[j] + p*(Arr[i-1][j]-(2*Arr[j])+ Arr[i+1][j]) 
                                              + p*(Fixed[j-1]-(2*Fixed[j])+ Fixed[j+1]);                     
       iter++;
      }while (((test -  Arr[1][1]) > 0.0001) || ((Arr[1][1] - test) > 0.0001));  
      return iter;
} 
avatar Re: Assignment 5 - Question 3
July 05, 2007 03:58AM
heya keith, you're way ahead of me (as usual!) so unfortunately i can't helping q3 yet.

as soon as i'm finished with q2 i'll check out q3!
Re: Assignment 5 - Question 3
July 09, 2007 11:33AM
When you have results for Q2 - Post them and lets compare.
Sorry, only registered users may post in this forum.

Click here to login