Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need this in C (not Cpp) and it needs to run on visual basic Summary: The temp

ID: 665538 • Letter: I

Question

I need this in C (not Cpp) and it needs to run on visual basic

Summary: The temperature distribution in a thin, square, metal plate with isothermal temperatures on each side can be modeled using a two-dimensional grid, as shown in Figure 1. We’ll use a simple 5 * 5 interior grid-point pattern.

Figure 1: Metal Plate with defined, constant temperatures on each of the 4 sides

Detail: A thin, square heat conductive plate is embedded on all 4 sides in a medium with fixed temperatures. The sides are called Top, Bottom, Left, andRight. All interior points are of 0 oC degree initially, but may change over time as heat flows. At the start of execution you enter the 4 temperatures of the 4 sides within reasonable physical limits (i.e. >= -273 and <= 1538 oC), yet all points on any same side have the same, constant temperature. Time is simulated via an outer loop, that progresses in discrete time steps. Each interior point changes its temperature as a function of the average of its 4 adjacent neighbors up, down, left, and right; you don't need to consider the diagonal points. When two successive iterations at grid point [1][1] show no more than a predefined ?T of temperatures the simulation stops. (Note that selecting grid points like [1][1] for temperature change tests is arbitrary and imprecise, yet is allowed as a simplification.)

If the interior points are initially zero, and there exists at least one side whose temperature is not zero, then the system is in a non-equilibrium state. Heat will flow from areas of higher to areas of lower temperature until thermal equilibrium is achieved and the temperature of all plate points becomes constant.

Programming hint: two separate 2D arrays should be used. One array contains the current iteration's grid temperatures, while the other array holds the next grid temperatures, which are computed using the data from the current iteration. After the new state has been calculated, it will become the current state for the next iteration.

Table 1: Required Test Cases, Temperatures in oC

Case

Top

Bottom

Left

Right

1

100

10

100

200

2

75

0

10

-25

3

50

50

50

50

4

Your data

Your data

Your data

Your data

Write a C program to model the temperature distribution for a plate with 5×5 interior grid points:

Prompt the user to enter the temperature (in degrees Celsius) of each of the 4 sides; these must be >= -273 oC, and <= 1,538 oC. Check for correctness.

All grid points along any one side have the same, constant temperature.

Each side can have a temperature that is different from any of the other sides, provided it is within legal range, but they may also be the same.

Use ?T = 10-2 ºC as the limit to stop further iterations.

At each iteration display the iteration number and the current temperature state in a nicely formatted table.

Show temperatures to two decimal places.

The output should include both the side and interior temperatures of the plate.

Quality and Resulting Points: Only homework that works correctly receives a passing grade. Proper commenting is crucial for a good solution. Describe in a brief paragraph each library you included. Also, for each function of a library you used, provide a single paragraph synopsis. If you did not include any library, explain, e.g. why <stdio.h> or the like is not needed. Test your running as long as the required precision (delta of temperature differences) has not yet been reached. (Note that the output below shows all 5 * 5 interior grid points, but also displays the neighboring rows and columns 0 and 6 for the sake of completeness; yet points [0][0], [0][6] etc. are never recomputed as a simplification.)

Table 2: Plausible input / Output

Enter temperatures (-273 oC .. 1538 oC) for all 4 sides of a plate below.

Enter Top temperature: 100

You entered 100.00 for Top side.

Enter Bottom temperature: 50

You entered 50.00 for Bottom side.

Enter Left temperature: 10

You entered 10.00 for Left side.

Enter Right temperature: 20

You entered 20.00 for Right side.

        Iteration # 0

                 0       1       2       3       4       5       6

        0:    0.00 100.00 100.00 100.00 100.00 100.00    0.00

        1:   10.00   27.50   25.00   25.00   25.00   30.00   20.00

        2:   10.00    2.50    0.00    0.00    0.00    5.00   20.00

        3:   10.00    2.50    0.00    0.00    0.00    5.00   20.00

        4:   10.00    2.50    0.00    0.00    0.00    5.00   20.00

        5:   10.00   15.00   12.50   12.50   12.50   17.50   20.00

        6:    0.00   50.00   50.00   50.00   50.00   50.00    0.00

        Iteration # 1

                 0       1       2       3       4       5       6

        0:    0.00 100.00 100.00 100.00 100.00 100.00    0.00

        1:   10.00   34.38   38.12   37.50   38.75   37.50   20.00

        2:   10.00   10.00    6.88    6.25    7.50   13.75   20.00

        3:   10.00    3.75    0.62    0.00    1.25    7.50   20.00

        4:   10.00    6.88    3.75    3.12    4.38   10.62   20.00

        5:   10.00   18.75   19.38   18.75   20.00   21.88   20.00

        6:    0.00   50.00   50.00   50.00   50.00   50.00    0.00

        Iteration # 2

                 0       1       2       3      4       5       6

        0:    0.00 100.00 100.00 100.00 100.00 100.00    0.00

        1:   10.00   39.53   44.69   45.78   45.62   43.12   20.00

        2:   10.00   13.75   13.75   12.97   15.00   18.12   20.00

        3:   10.00    6.88    3.59    2.81    4.84   11.41   20.00

        4:   10.00    9.06    7.50    6.72    8.75   13.44   20.00

        5:   10.00   21.56   22.81   23.12   23.75   25.16   20.00

        6:    0.00   50.00   50.00   50.00   50.00   50.00    0.00

        Iteration # 3

                 0       1       2       3       4       5       6

        0:    0.00 100.00 100.00 100.00 100.00 100.00    0.00

        1:   10.00   42.11   49.77   50.82   50.98   45.94   20.00

        2:   10.00   17.54   18.75   19.34   20.39   22.38   20.00

        3:   10.00    9.10    7.73    7.03    9.49   14.10   20.00

        4:   10.00   11.48   10.55   10.55   12.19   16.33   20.00

        5:   10.00   22.97   25.55   25.82   26.76   26.80   20.00

        6:    0.00   50.00   50.00   50.00   50.00   50.00    0.00

Case

Top

Bottom

Left

Right

1

100

10

100

200

2

75

0

10

-25

3

50

50

50

50

4

Your data

Your data

Your data

Your data

Explanation / Answer

Answer:

//CPP program for temperature convergence in a metal plate

#include <iostream>

#include<string>

#include <cmath>

//DEFINE THE TEMPERATURE TOLERANCE

#define deltemp 0.01

using namespace std;

double fun_maxTemp(double diff_temp[][gridCol], int gridRow);

//main MEthod

int main()

{

int gridRow,gridCol;

double grid1[10][10];

double grid2[10][10];

double diff_temp[10][10];

int iteration_count=0;

//GET NUMBER OF ROWS AND NUMBER COLUMNS IN THE GRID

cout<<" Enter the grid row:";

cin>>gridRow;

cout<<" ENTER GRID COLUMN";

cin>>gridCol;

//GET THE FOUR SIDES TEMPERATURE

do

{

cout<<"ENTER TOP TEMPERATURE";

cin>>top_temp;

}while(top_temp>=-273&&top_temp<=1538.00);

do

{

cout<<" ENTER BOTTOM TEMPEATURE:";

cin>>down_temp;

}while(down_temp>=-273&&down_temp<=1538.00);

do

{

cout<<" eNTER THE LEFT TEMPERATURE:";

cin>>left_temp;

}while(left_temp>=-273&&left_temp<=1538.00);

do

{

cout<<" eNTER THE RIGHT TEMPERATURE:";

cin>>right_temp;

}while(right_temp>=-273&&right_temp<=1538.00);

//INITIALIZES THE GRID1 AND GRID2

for(int k1=0;k1<(gridRow+2);k1++)

{

for(int k2=0;k2<(gridCol+2);k2++)

{

if (k1==0)

{

grid1[k1][k2]=top_temp;

grid2[k1][k2]=top_temp;

}

else if(k1==(gridRow+1))

{

grid1[k1][k2]=down_temp;

grid2[k1][k2]=down_temp

}

else if(k2==0)

{

grid1[k1][k2]=left_temp;

grid2[k1][k2]=left_temp;

}

else if(k2==(gridCol+1))

{

grid1[k1][k2]=right_temp;

grid2[k1][k2]=right_temp;

}

else if(k1==k2)

{

grid1[k1][k2]=0.00;

grid2[k1][k2]=0.00;

}

else

{

grid1[k1][k2]=0.00;

grid2[k1][k2]=0.00;

}

}

}

do

{

//FIND NEW TEMPERATURE

for (int k1 = 1; k1 < =gridRow; k1++)

{

for (int k2 = 1; k2<= gridCol;k2++)

{

grid2[k1][k2] = 0.25 * (grid1[k1+1][k2] + grid1[k1-1][k2] + grid1[k1][k1+1] + grid1[k1][k2-1]);

}

}

//FIND THE DIFFERENCE BETWEEN OLD AND NEW TEMPERATURE

for (int m1=0;m1<(gridRow+2);m1++)

{

for (int m2=0;m2<(gridCol+2);m2++)

{

diff_temp[m1][m2] = grid2[m1][m2] - grid1[m1][m2];

}

}

//DISPLAY THE GRID FOR EACH ITERATION

cout<<" Iteration:#"<<iteration_count;

for(int k1=0;k1<(gridRow+2);k1++)

{

cout << " ";

for(int k2=0;k2<(gridCol+2);k2++)

{

cout << grid2[k1][k2] << " ";

}

}

//ASSIGN NEW TEMPERATURE TO OLD TEMPERATURE

for (int k1 = 1; k1 < =gridRow; k1++)

{

for (int k2 = 1; k2<= gridCol;k2++)

{

grid1[k1][k2] = grid2[k1][k2];

}

}

iteration_count++;

}while(fun_maxTemp(diff_temp[][],gridRow)<deltemp);

cout<<"TEMPERTURE CIONVERGES:";

return 0;

}

double fun_maxTemp(double diff_temp[][gridCol], int gridRow)

{

int n1,n2;

double max_temp=0.00;

for (n1 = 0; n1 < 10; n1++)

for (n2 = 0; n2 < 10; n2++)

if (fabs(diff_temp[n1][n2]) > max_temp)

max_temp = fabs(diff_temp[n1][n2]);

}

return max_temp;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote