Gain experience with 2-dimensional arrays and loops while solving a real-world problem (“steady state analysis”).

In this assignment you will compute the steady state temperature distribution over a piece of metal. This steady state analysis solves a system of partial differential equations numerically and is used in solving many physics problems. Similar matrix algorithms are also used in analyzing airplane wing and automobile pressure distributions through fluid flow dynamics simulations.

- Use a 2D array and calculate the steady-state temperature of each element in it
- Write the array to a CSV (“comma separated values”) file
- Plot the results of the CSV using excel

The problem is to determine the temperature distribution for a two-dimensional plate with constant boundary conditions. Use a 20 X 20 two dimensional array to represent pieces of the plate. The elements on the boundaries have fixed temperatures. The elements on the top and bottom row have a fixed temperature of 100 degrees. The elements on the leftmost and rightmost columns have a temperature of zero degrees. (The corner elements have a temperature of zero degrees.)

The job of the algorithm is to find the steady-state temperature distribution of the interior elements. “Steady state means that the temperature of any cell is approximately equal to the average of the temperatures of its four neighbors on the north, south, east, and west directions.

To calculate the new temperature value of an array element, take the average of the values in the 4 direct neighbors of that cell

For example, the cell at position array[1][2] currently has a value of 60.6 degrees. At the next iteration, it will be set to the average of its 4 neighbors (100.0 + 66.3 + 34.0 + 45.2)/4

You should continue to iterate until no cell in the array changes more than 0.1 degree, calculating the temperature for all interior cells on each iteration.

When you are finished, you should write your two dimensional array out to a comma separated values file like this:

0.0,100.0,100.0,100.0, 0.0,45.1,60.6,66.2,0, 0.0,45.1,60.6,66.2,0, 0.0,100.0,100.0,100.0,0,

You can import this csv file into a spreadsheet like excel and format it as a 3d graph in order to check your work.

You should think about how you could break the program up into methods to make each task smaller and easier to accomplish.

Work through some small examples by hand and think about the array index you will have to use to get to adjacent array elements.

Think about how you will check to see if your code is performing correctly. Decide on what the overall answer should be and then write tests that will make sure that your methods are performing appropriately.

You can find out more about how to write to a file in example FileIO

Start by writing a method to print out your array, then write the code to initialize the boundaries, then write the iteration code and progressively solve small pieces of your problem.

To graph your data, import the csv file into excel as a csv file, then select the data and create a 3d chart. Follow this tutorial if you're unfamiliar with Excel: Export To Excel

When you have your program working, you will need to show it to a TA. The TA will evaluate your code based on the following criteria:

- Initialize your two dimensional array correctly and print it out. (5 points)
- Update elements in the array correctly for at least one iteration. (5 points)
- Stop when there is less than a 0.1 degree change for all elements. (10 points)
- Save out your array to a CSV file (5 points)
- Plot your final array using excel (5 points)
- Is your code properly formatted (indenting blocks, comments, spacing, reasonable names of variables)? (5 points)

Extra Credit: Pass off early (1 point per day (excluding Sunday) up to 3 points)