'How do I calculate a change in value from a 2D Array?
I'm working on a project that uses a 2D array. The inside (anything that isn't on the edge of the array) of the array has each cell averaging out based on the four values touching it. The values are supposed to keep updating until the change in value (new array value - previous value in array) is less than a number input by the user called epsilon. This change in value has to be less than epsilon for each and every index. So how would I go about checking each change in index value to epsilon? I was thinking about storing the change in a new array and checking each index to epsilon but the way I implemented it didn't work. You can ignore the tempChange array I didn't remove it incase someone wanted to build off of what I wrote. Here is my code:
void determineInteriorTemp(double tempArr[26][30], int rowArr, int colArr, double epsilon)
{
int iteration = 0;
double tempChange[26][30] = { 300 };
for (int x = 1; x < rowArr - 1; x++)
{
for (int y = 1; y < colArr - 1; y++)
{
while (tempChange[x][y] > epsilon)
{
tempArr[x][y] = (tempArr[x - 1][y] + tempArr[x + 1][y] + tempArr[x][y + 1] + tempArr[x][y - 1]) / 4; //update
tempChange[0][0] = tempArr[x][y] - tempChange[x][y];
}
}
}
iteration++;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
