Really I need a whole program for the answer, not just the ideas. Please help!!!
ID: 3546432 • Letter: R
Question
Really I need a whole program for the answer, not just the ideas. Please help!!! My homework deadline is in 1 hour!!
Temperature Distribution. The temperature distribution in a thin metal plate with constant (or isothermal) termperatures on each side can be modeled using a two-dimensional grid. 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 accordng to the temperatures around them. Assume that the temperature of an interior point can be computed as the average of the four adjacent temperatures. 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.
- 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 tolerance value. Use the vector class to implement the grid.
Explanation / Answer
#include"stdio.h"
#include"math.h"
#include"stdlib.h"
int main()
{
printf("Enter the temperature T1 T2 T3 T4");
float t1,t2,t3,t4;
scanf("%f",&t1);
scanf("%f",&t2);
scanf("%f",&t3);
scanf("%f",&t4);
int i=0,j=0;
float temp[100][100];
for(i=0;i<10;i++)
for(j=0;j<10;j++)
temp[i][j]=0; // Set initial temperature as 0
for (i=0;i<8;i++)
temp[i][0]=t2; // Set boundary temperature
for (i=0;i<8;i++)
temp[i][6]=t4;
for (j=0;j<6;j++)
temp[0][j]=t1;
for (j=0;j<8;j++)
temp[8][j]=t3;
for(i=1;i<8;i++)
for(j=1;j<6;j++)
temp[i][j]=(temp[i+1][j-1]+temp[i+1][j+1]+temp[i-1][j-1]+temp[i-1][j+1])/4; // Calculate temperatures of inner points
printf(" Temperatures are ");
for(i=0;i<8;i++)
{
for(j=0;j<6;j++)
{
printf("%f% ",temp[i][j]);
}
printf(" ");
}
system("pause");
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.