hwk13 (1)

2
EL2008 Homework #13 Semester II 2013/14 Due Date: April 3, 2014  This program will do a temperature simulation of a sheet of metal that has been divided up into 100 rows and 100 columns of cells. Initial temperatures are ass igned to each cell and then the simulation is run until the temperatur e of the metal sheet reaches a steady state. The program will be divided up into several functions. The first function will initiali ze each cell on the sheet to a starting temperature. The layer of cells on the edge of the sheet will all be set to 10 degrees. The 18 th  row of cells will be set to 20 degrees except for the ends of the r ow which were set t o 10. The rest of the cells on the plate will be set to 15 degrees. This function does no t have a return value and will only serve to i nitialize the temperatures in the array. The next function will perform the simul ation. Each new cell temperature will be the average of the temperatures of the four surrounding cells (up, down, left and right) from the previous array of temperatures. The cells around the edge of the array will not be changed. Run the simulation until the difference of the absolute value of two consecutive averages is less than 0.01 degrees. Return the number of iterations needed for the simulation to the main program. Two functions will be called from the simulation function. First, write a function to compute the average temperature for the sheet of metal. Take into account the temperatures of t he cells around the edges when computing the average. Call this function for the initial temperature distribution and for each subsequent it eration. Store the average t emperature returned f rom this function into a 1-dimensional array for output later. Also, call a function which copies the new temperatur e array to the old array in preparation for the next update. This function will not have a return value but will simply copy the contents of one 2-dimensional array to another. The last function called from main will print the number of iterations needed to reach steady state and then print a column of iteration numbers and a column of temperatures. The temperature a t iteration 0 represents the averag e temperature of the initial values. Format the output as follows: Number of Iterations: 28 Iteration Average  Number Temperature  0 14.85  1 14.80  2 14.77  . .  . .  . .

Upload: merakarno-rahusna-taruno

Post on 03-Jun-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

8/12/2019 hwk13 (1)

http://slidepdf.com/reader/full/hwk13-1 1/2

EL2008 Homework #13 Semester II 2013/14

Due Date: April 3, 2014

This program will do a temperature simulation of a sheet of metal that has been divided up into 100rows and 100 columns of cells. Initial temperatures are assigned to each cell and then the simulationis run until the temperature of the metal sheet reaches a steady state. The program will be dividedup into several functions.

The first function will initialize each cell on the sheet to a starting temperature. The layer of cellson the edge of the sheet will all be set to 10 degrees. The 18 th row of cells will be set to 20 degreesexcept for the ends of the row which were set to 10. The rest of the cells on the plate will be set to15 degrees. This function does not have a return value and will only serve to initialize thetemperatures in the array.

The next function will perform the simulation. Each new cell temperature will be the average of thetemperatures of the four surrounding cells (up, down, left and right) from the previous array of temperatures.

The cells around the edge of the array will not be changed. Run the simulation until the differenceof the absolute value of two consecutive averages is less than 0.01 degrees. Return the number of iterations needed for the simulation to the main program.

Two functions will be called from the simulation function. First, write a function to compute the

average temperature for the sheet of metal. Take into account the temperatures of the cells aroundthe edges when computing the average. Call this function for the initial temperature distribution andfor each subsequent iteration. Store the average temperature returned from this function into a1-dimensional array for output later. Also, call a function which copies the new temperature arrayto the old array in preparation for the next update. This function will not have a return value but willsimply copy the contents of one 2-dimensional array to another.

The last function called from main will print the number of iterations needed to reach steady stateand then print a column of iteration numbers and a column of temperatures. The temperature a titeration 0 represents the average temperature of the initial values. Format the output as follows:

Number of Iterations: 28Iteration Average Number Temperature 0 14.85 1 14.80 2 14.77 . . . . . .

8/12/2019 hwk13 (1)

http://slidepdf.com/reader/full/hwk13-1 2/2

Figure 1 . Program structure

Use fopen/fprintf/fclose to write the data to a file called hwk13.out .

Submit the homework when you have the code and documentation completed.