The temperature distribution in a thin metal plate with cons

The temperature distribution in a thin metal plate with constant (or isothermal) temperatures on each side can be modeled using a two-dimensional grid, as shown in Figure Typically, the number of points in the grid are specified, as are the constant temperatures on the four sides. The temperatures of the interior points are usually initialized to zero, but they change according to the temperatures around them. Assume that the temperature of an interior point can be computed as the average of the four adjacent temperatures; the points shaded in represent the adjacent temperatures for the point labeled x in the grid. Each time that the temperature of an interior point changes, the temperatures of the points adjacent to it change. These changes continue until a thermal equilibrium is achieved and all temperatures become constant. Figure Temperature grid in a metal plate. Write a program to model this temperature distribution for a grid with six rows and eight columns. Allow the user to enter the temperatures for the four sides. Use one grid to store the temperatures. Thus, when a point is updated, its new value is used to update the next point. Continue updating the points, moving across the rows until the temperature differences for all updates are less than a user-entered tolerance value. Use the vector class to implement the grid.

Solution

Here is the code for you:

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
double Array[35][20], left, right, top, bottom, temp, epsilon;
int ROWS, COLS, count = 0;
bool equilibrium = false;

cout<<\"Enter the size of the plate ROWSxCOLS: \";
cin>>ROWS;
cin>>COLS;
cout<<\"Enter the temperature at the top edge: \";
cin>>top;
cout<<\"Enter the temperature at the bottom edge: \";
cin>>bottom;
cout<<\"Enter the temperature at the left edge: \";
cin>>left;
cout<<\"Enter the temperature at the right edge: \";
cin>>right;
for(int i = 0; i < ROWS; i++)   //Initializing all the array values to 0.
for(int j = 0; j < COLS; j++)
Array[i][j] = 0;
for(int i = 1; i < COLS-1; i++)   //Initializing top edge.
Array[0][i] = top;
for(int i = 1; i < ROWS-1; i++)   //Initializing left edge.
Array[i][0] = left;
for(int i = 1; i < COLS-1; i++)   //Initializing bottom edge.
Array[ROWS-1][i] = bottom;
for(int i = 1; i < ROWS-1; i++)   //Initializing right edge.
Array[i][COLS-1] = right;
Array[0][0] = (top + left) / 2;   //Calculating corner values.
Array[0][COLS-1] = (top + right) / 2;
Array[ROWS-1][0] = (left + bottom) / 2;
Array[ROWS-1][COLS-1] = (bottom + right) / 2;   
cout<<\"Enter the epsilon value: \";   //Read epsilon value.
cin>>epsilon;
cout<<\"Initial temperatures in the array: \"<<endl;   //Print initial temperatures.
for(int i = 0; i < ROWS; i++)
{
for(int j = 0; j < COLS; j++)
cout<<fixed<<setprecision(2)<<Array[i][j]<<\" \";
cout<<endl;
}
while(!equilibrium)           //Modifying the temperatures, and running the loop.
{
equilibrium = true;
for(int i = 1; i < ROWS-1; i++)
for(int j = 1; j < COLS-1; j++)
{
temp = (Array[i-1][j] + Array[i+1][j] + Array[i][j-1] + Array[i][j+1]) / 4;
if(abs(temp - Array[i][j]) > epsilon)
equilibrium = false;
Array[i][j] = temp;
}
count++;
}
cout<<\"The plate reached equilibrium after \"<<count<<\" iterations.\"<<endl;
cout<<\"Final temperatures in the array: \"<<endl;   //Print final temperatures.
for(int i = 0; i < ROWS; i++)
{
for(int j = 0; j < COLS; j++)
cout<<setw(5)<<fixed<<setprecision(2)<<Array[i][j]<<\" \";
cout<<endl;
}
}

 The temperature distribution in a thin metal plate with constant (or isothermal) temperatures on each side can be modeled using a two-dimensional grid, as show
 The temperature distribution in a thin metal plate with constant (or isothermal) temperatures on each side can be modeled using a two-dimensional grid, as show

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site