我想弄清楚数组的epsilon?

时间:2015-04-15 00:53:35

标签: c++ arrays epsilon

我在C ++学习初学者课程,我的项目包括使用二维数组。我在找到epsilon时感到困惑,数组中的所有单元格都小于这个数字。

示例中使用的数字是

  1. Top = 100
  2. Bottom = 90
  3. 左= 75
  4. 右= 75

  5. do
    {
        if (counter == 0)
        {
            difference = 0.0;
            //Next set the top-right, top-left, bottom-left, bottom-right values to the array, as well as comparing the inner values of the array.
            for (int x = 0; x < rows; x++)
            {
    
                for (int y = 0; y < columns; y++)
                {
    
                    //Get the top left corner's value
                    plate[0][0] = (plate[0][1] + plate[1][0]) / 2.0;
    
                    //Get the top right corner's value
                    plate[0][columns - 1] = (plate[0][columns - 2] + plate[1][columns - 1]) / 2.0;
    
                    //Get the bottom left corner's value
                    plate[rows - 1][0] = (plate[rows - 2][0] + plate[rows - 1][1]) / 2.0;
    
                    //Get the bottom right corner's value
                    plate[rows - 1][columns - 1] = (plate[rows - 1][columns - 2] + plate[rows - 2][columns - 1]) / 2.0;
    
                    if (x > 0 && x < (rows - 1) &&
                        y > 0 && y < (columns - 1))
                    {
                        plate[x][y] = (plate[x + 1][y] + plate[x - 1][y] + plate[x][y + 1] + plate[x][y - 1]) / 4.0;
                        difference = plate[x][y] - difference;
                    }
    
                    cout << setw(5) << showpoint << right << setprecision(1) << fixed << plate[x][y] << " ";
                }
                cout << endl;
            }
            cout << endl;
            counter++;
        }
        else
        {
            for (int x = 0; x < rows; x++)
            {
    
                for (int y = 0; y < columns; y++)
                {
    
                    if (x > 0 && x < (rows - 1) &&
                        y > 0 && y < (columns - 1))
                    {
                        plate[x][y] = (plate[x + 1][y] + plate[x - 1][y] + plate[x][y + 1] + plate[x][y - 1]) / 4.0;
                        difference = plate[x][y] - difference;
                    }
                    cout << setw(5) << showpoint << right << setprecision(1) << fixed << plate[x][y] << " ";
                }
                cout << endl;
            }
            counter++;
            cout << endl;
        }
    } while (difference > epsilon);
    

0 个答案:

没有答案