Question: This is a C++ problem. Please give full explanations and code in details. Thanks. Problem Statement: Imagine a thin metal plate surrounded by heat sources

 This is a C++ problem. Please give full explanations and code

in details. Thanks. Problem Statement: Imagine a thin metal plate surrounded by

heat sources along each edge, with the edges held at different tem-

This is a C++ problem. Please give full explanations and code in details. Thanks.

Problem Statement: Imagine a thin metal plate surrounded by heat sources along each edge, with the edges held at different tem- peratures. After a short time, the temperature at each location on the plate will settle into a steady state. This can be modeled by dividing the plate into a discrete grid of cells and simulating the change in temperature of each cell over time: 100 100 100 100 100 90 90 T(2,1) T(2,2T(2,3)95 90 T3,1)T(3,2)T(3,3)95 80 80 80 80 80 At each time step, the temperature in each interior cell (ij) will be the average of four of its surrounding neighbors T(i,j)-(T(i-1,j) + T(it1,j)+ T(i,j-1) + T(i.j+1))/4 So develop a program to determine the steady state temperature distribution in the plate by representing the plate as a two-dimensional array with NROWS rows and NCOLS columns. NROWS and NCOLS should be de- clared as global constants (suggestion: use 5 for both values at first, but increase this to 20 once you get your program working.). Your program should do the following: Declare 2 separate two-dimensional arrays named temp and old. Array old will be used to main- tain the current values of the grid temperatures and array temp will be used to compute the new val ues obtained at each successive time step using the equation above Prompt the user and enter temperature values for the top, bottom, left, right sides. Also prompt and enter an initial temperature T(ij) for the interior cells. (For this lab, you may initialize all the interior cells to a single, user-input temperature.) Initialize temp using these values and display the initial contents of the temp array on the console .Obtain a convergence criterion (call it tol) from the user (say, for example, 0.001) .Use a convergence loop to continue updating the temp array until the temperature in every cell con- verges using the following method 1. Set a boolean variable named steady to true 2. Copy temp to old 3. Loop over all the interior cells (but not the edge cells!) temp [i][0.25* (old[i] [j-1]+ . .) If Itemp [i] [j]-old[i][j tol, then set steady to false Repeat this 3-step process again and again until all the cells simultaneously satisfy the convergence criterion i.e., steady remains true after all cells are checked. This is a longer program than usual, so here are a number of hints: . Before writing any code think about what the code should look like: What will an outline look like? Will it involve loops? If so, how many, where, and of what type? Will there be if statements? If so, where and how many? What variables will your program need to keep track of? Which of these will be arrays? Think about these questions and discuss them with your partner before actually writing any code. Write, test, and debug your code incrementally, rather than all at once. Create a function named void display (double temp [] (NCOLS]). You can use this function to print out that array at any time, and so the function will be useful in debugging your program. Make sure you can explain the difference between the old array and the temp array, and why your pro- gram needs to use both. Make sure you understand how to have your program loop through only the interior of the array. Make sure you understand what the convergence criterion test is, and what role it plays in your program

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!