<p> </p> <p><span style=\"font-size: small;\">The temperature distribution
ID: 3625979 • Letter: #
Question
<p> </p><p><span>The temperature distribution in a thin metal plate with constant (or isothermal) temperatures on each side can be modeled by using a two dimensional grid as shown below. </span></p>
<p><span>The grid plate has 6 rows and 8 columns, it goes from top to bottom and from left to right.</span> </p>
<p><span>Temperature Grid in a Metal Plate
<p>Typically, the number of points in the grid is specified, as are the constant temperatures on the four sides. The temperatures of the interior point 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 above represent the adjacent temperatures for the point labeled x in the grid. Each time the temperature of an interior point changes, the temperatures of the points adjacent to it change, except for the edge points, which remain constant. These changes continue until a thermal equilibrium is achieved and all temperatures become constant.</p>
<p>1. (70 pts) Write a program to model this temperature distribution for a grid with six rows and eight columns.</p>
<span>
<p>a. Read in an initial temperature distribution from a data file. Prompt the user to enter a file name. There is a set of data in a file named</p>
</span><strong><span><strong><span>initialtemps.txt</span></strong></span></strong><span>. The format of the file is 6 rows of 8 numbers. Use one 2 dimensional array to store the temperatures. </span></span></p>
<p><span>
<p>b. Allow the user to modify the initial distribution, after it is read, by specifying new values for the points on the four sides of the grid (top, left, right, and bottom as shown above). Since the user may want to change only a few of the edge grid points, prompt</p>
<p>the user to enter the row and column indices of the grid point to change. This should be in a loop that will allow the user to change as many points as desired.</p>
</span></p>
Explanation / Answer
#include <stdio.h>
#include <math.h>
#define NROWS 6
#define NCOLS 8
int main(void)
{
double left_t,right_t,top_t,bot_t,dtmax = 0.0,tolerance;
double plate1[NROWS][NCOLS]={{0}},plate2[NROWS][NCOLS]={{0}};
int row,col;
printf("Enter the temperatures of the left, right, top, and bottom edges of the plate: ");
scanf("%lf %lf %lf %lf",&left_t,&right_t,&top_t,&bot_t);
printf("Enter the tolerance value:");
scanf("%lf",&tolerance);
for (col=0; col<NCOLS; col++)
{
plate1[0][col] = plate2[0][col] = top_t;
plate1[NROWS-1][col] = plate2[NROWS-1][col]=bot_t;
}
for (row=0; row<NROWS-1; row++)
{
plate1[row][0] = plate2[row][0] = left_t;
plate1[row][NCOLS-1] = plate2[row][NCOLS-1]=right_t;
}
do
{
dtmax=0;
for (row=1;row<NROWS-1;row++)
for (col=1;col<NCOLS-1;col++)
{
plate2[row][col] = (plate1[row-1][col] + plate1[row+1][col] + plate1[row][col-1] + plate1[row][col+1])/4;
if (fabs(plate2[row][col]-plate1[row][col])>dtmax)
dtmax = fabs(plate2[row][col]-plate1[row][col]);
}
printf("dtmax:%.2f ",dtmax);
for (row=1; row<NROWS-1;row++)
for (col=1;col<NCOLS-1;col++)
plate1[row][col] = plate2[row][col];
}while (dtmax>tolerance);
for (row=0;row<NROWS;row++)
{
for (col=0;col<NCOLS;col++)
printf("%5.0f",plate1[row][col]);
printf(" ");
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.