Я пытаюсь выяснить эпсилон массива?

Я беру класс для начинающих в C++, и мой проект состоит из использования 2-D массивов. Я запутался в поиске эпсилона, все ячейки в массиве меньше этого числа.

Числа, использованные в примере:

  1. Top = 100
  2. Низ = 90
  3. Слева = 75
  4. Справа = 75

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 ответов

Другие вопросы по тегам