【发布时间】:2015-10-30 06:30:43
【问题描述】:
这段代码的一部分我需要帮助。此代码正在计算板上的稳态温度分布。我收到的提示是:
您应该继续迭代,直到数组中没有单元格的变化超过 0.1 度,计算每次迭代时所有内部单元格的温度。您的程序应监控数组中任何单元格的最大变化,以确定何时停止重复。
我被困住了!我目前正在使用 while 循环来获得正确的答案,但我只是不知道如何让它完成提示中要求我做的事情。任何帮助将非常感激!
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
const int SIZE = 20;
const double HEAT = 100;
const double EDGES = 0;
const int SURROUNDING = 4;
const int STABLE = .1;
// Initializes the first array
void begining_plate ( double plate[][SIZE]) {}
// Calculates one ideration of the steady-state distribution
double average_temp_calc(double plate[][SIZE], int a, int b) {}
// Prints the array
void print_plate( double plate[][SIZE]) {
// Exports the array to a .csv file
bool send_plate_info(double plate[][SIZE])
int main() {
// Part 1 - Initialize and Print 2D Array
cout << "Here is the initial heat: " << endl;
double plate[SIZE][SIZE];
begining_plate(plate);
print_plate(plate);
// Part 2 - Update Elements once
double plate_saved[SIZE][SIZE];
cout << "\nHere is the first run of the averaged plate.\n";
for (int a = 0; a < SIZE; a++) {
for (int b = 0; b < SIZE; b++) {
if (a != 0 && a != SIZE - 1 && b != 0 && b != SIZE - 1) {
plate_saved[a][b] = plate[a][b];
plate[a][b] = average_temp_calc(plate, a, b);
}
else {
plate_saved[a][b] = plate[a][b];
plate[a][b] = plate[a][b];
}
}
}
print_plate(plate);
cout << endl << endl;
// Part 3 - Repeat update until stalbe
******* HERE IS THE PART I NEED HELP WITH **********
int count = 0;
int stable = 150;
while (count < stable) {
for (int a = 0; a < SIZE; a++) {
for (int b = 0; b < SIZE; b++) {
if (a != 0 && a != SIZE - 1 && b != 0 && b != SIZE - 1) {
plate_saved[a][b] = plate[a][b];
plate[a][b] = average_temp_calc(plate, a, b);
}
else {
plate_saved[a][b] = plate[a][b];
plate[a][b] = plate[a][b];
}
}
}
count++;
}
// Part 4 - Using Excel to Display Results
if (send_plate_info(plate))
{
cout << "File wrote correctly\n";
}
else
{
cout << "The file did not write!\n";
}
system("pause");
return 0;
}
【问题讨论】:
-
我看到你的评论说你自己解决了额外的问题,恭喜:-)