Homework 4(Due:11:00 pm March.23) The basic description of the project is given in following detail description.But the project requirement is specified here(which is a little different from the original one): Your job in this project is to design a heater system for a given room.Your job is divided into two parts: 1.You are going to write a function called heating.m to simulate the temperature distribution of a room for a given set of conditions specified by roomSize and initT. 2.You are going to make your own design of the heater system by specify it's location, size,and temperature so that the average temperature is controlled between 21 and 22 degrees of centigrade and variation is within 2 degrees of centigrade(the best one goes to the one minimize the energy consume as well as the algorithm efficiency measured by the time t,for the duration of the while loop). Write your design reason and process in a word document and save your heater data into a file called mydesign.mat.It contains your design data roomSize and initT. You do this for room size 48 by 32. This data(mydesign.mat)should be saved as a binary file and should be turned in together with your heating.m file as well as the mydesign.doc. Requirement of the assignment 1.Write a function called heating.m for the project Function declaration function [T,average,variation,t]heating (roomSize,initT, where: roomSize is a 1 by 5 row vector,containing roomSize(1)rowN of the room cells roomSize(2)colN of the room cells roomSize(3)window size (location is specified by the problem) roomSize(4)lower left corner of the heater in the room roomSize(5)upper right corner of the heater in the room Hint: you need to know how to translate two dimensional array index with a single value you can assume that the shape of the heater is always a rectangle one
Homework 4 (Due: 11:00 pm March. 23) The basic description of the project is given in following detail description. But the project requirement is specified here (which is a little different from the original one): Your job in this project is to design a heater system for a given room. Your job is divided into two parts: 1. You are going to write a function called heating.m to simulate the temperature distribution of a room for a given set of conditions specified by roomSize and initT. 2. You are going to make your own design of the heater system by specify it’s location, size, and temperature so that the average temperature is controlled between 21 and 22 degrees of centigrade and variation is within 2 degrees of centigrade (the best one goes to the one minimize the energy consume as well as the algorithm efficiency measured by the time t, for the duration of the while loop). Write your design reason and process in a word document and save your heater data into a file called mydesign.mat. It contains your design data roomSize and initT. You do this for room size 48 by 32. This data (mydesign.mat) should be saved as a binary file and should be turned in together with your heating.m file as well as the mydesign.doc. Requirement of the assignment 1. Write a function called heating.m for the project Function declaration function [T, average, variation, t] = heating (roomSize, initT, ) where: roomSize is a 1 by 5 row vector, containing roomSize(1) rowN of the room cells roomSize(2) colN of the room cells roomSize(3) window size (location is specified by the problem) roomSize(4) lower left corner of the heater in the room roomSize(5) upper right corner of the heater in the room Hint: • you need to know how to translate two dimensional array index with a single value • you can assume that the shape of the heater is always a rectangle one
initT is a 1 by 4 row vector,containing initT(1):space temperature initT(2):wall temperature initT(3):window temperature initT(4):heater temprature T:is the final temperature array for room cells averageL:is the computed average of your simulation or design variation:is the computed variation of your simulation or design t:is the time duration(measured in seconds)required for the while loop 2.For good decomposition,you might want decompose your heating.m into a few small functions like roomSet and averageT as described bellow: function T roomSet (roomsize,initT); 8prepare data for picture in 11.1 function T averageT (oldT,roomSize); This function will be called in a while loop and 8 update temperature array oldT to T using the algorithm described in the problem specification If you do so,please pack all of them into a rar file and submit to Sakai together 3.Turn in your design document mydesign.doc and final data mydesign.mat together with your other MATLAB functions. Notes for submission: For this problem,You need pack all of your *.m files and design documents into a single file and submit it to the Sakai using attachment. Name you packed file in the following matter.The format is important,if you did not follow this rule,your homework may not be able to be grated correctly or on time. sYourlD_hwk3_1.rar Example s5073709022_hwk31.rar
initT is a 1 by 4 row vector, containing initT(1): space temperature initT(2): wall temperature initT(3): window temperature initT(4): heater temprature T: is the final temperature array for room cells averageL: is the computed average of your simulation or design variation: is the computed variation of your simulation or design t: is the time duration (measured in seconds) required for the while loop 2. For good decomposition, you might want decompose your heating.m into a few small functions like roomSet and averageT as described bellow: function T = roomSet (roomSize, initT); % prepare data for picture in 11.1 function T = averageT (oldT, roomSize); % This function will be called in a while loop and % update temperature array oldT to T using the algorithm % described in the problem specification If you do so, please pack all of them into a rar file and submit to Sakai together 3. Turn in your design document mydesign.doc and final data mydesign.mat together with your other MATLAB functions. Notes for submission: For this problem, You need pack all of your *.m files and design documents into a single file and submit it to the Sakai using attachment. Name you packed file in the following matter. The format is important, if you did not follow this rule, your homework may not be able to be grated correctly or on time. sYourID_hwk3_1.rar Example : s5073709022_ hwk3_1.rar
11.10.PROJECTS 327 11.10 Projects 1.Is your dorm room cold?-Register your complaint! Consider that your dorm room is represented by a 32x32 array,with 4 walls fixed at 20C,a window 16x1 centered on the left wall which is fixed at 0C (it's freezing outside),and a heat register comprised of 8 contiguous pixels (array elements that all touch another heat register array element on at least one side)that is fixed at some higher temperature.See Figure 1 for an example.Your job is to: (a)Locate the register in the room somewhere (not occupying the same space as a wall or a window!)so that the temperature in the room is as uniform as possible, (b)Heat the room to between 21 and 22C by raising the temperature of the register. (c)Full marks for algorithm design will be awarded to those who find a location for the heat register that keeps the temperature in the room uniform to within 2 degrees.(How to calculate this is discussed later. Here is a step-by-step procedure for this problem: (a)Open a file called a7.m with any editor.This will be your script M-file.Once in MATLAB,you will run this program by simply typing a7 at the MATLAB prompt. (b)To start the problem,first fill a 32x32 array with zeros: N=32; T zeros(N); (c)Then,make the first and last pixels of each row and column equal to 20,setting the temperature on the walls,then the 16 pixels of the window (fixed at 0)and finally the 8 pixels of the register (set at T=65C)as shown in Figure 1. The picture in Figure 1 is displayed using the following MATLAB commands: plotT T;Copy the T array plotT(N+1,:)=0;Increase the number of rows by 1 plotT(:,N+1)=0;Increase the number of columns by 1 pcolor(1:N+1,1:N+1,plotT);Plot it colorbar; Increasing the row and columns by 1 is necessary to get MATLAB to show the walls and the window,otherwise only the interior of the room would show. (d)Inside a while loop,the i,j'th cell gets it value from its neighbors,via an averaging relation of the form: T(i,j)=(o1dT(i+1,j)+o1dT(i-1,j)+o1dT(i,j+1)+o1dT(i,j-1)/4;
11.10. PROJECTS 327 11.10 Projects 1. Is your dorm room cold?—Register your complaint! Consider that your dorm room is represented by a 32×32 array, with 4 walls fixed at 20◦C, a window 16×1 centeredon the left wall which is fixedat 0◦C (it’s freezing outside), and a heat register comprised of 8 contiguous pixels (array elements that all touch another heat register array element on at least one side) that is fixed at some higher temperature. See Figure 1 for an example. Your job is to: (a) Locate the register in the room somewhere (not occupying the same space as a wall or a window!) so that the temperature in the room is as uniform as possible, (b) Heat the room to between 21 and22◦C by raising the temperature of the register. (c) Full marks for algorithm design will be awarded to those who find a location for the heat register that keeps the temperature in the room uniform to within 2 degrees. (How to calculate this is discussed later.) Here is a step-by-step procedure for this problem: (a) Open a file called a7.m with any editor. This will be your script M-file. Once in MATLAB, you will run this program by simply typing a7 at the MATLAB prompt. (b) To start the problem, first fill a 32×32 array with zeros: N = 32; T = zeros(N); (c) Then, make the first andlast pixels of each row andcolumn equal to 20, setting the temperature on the walls, then the 16 pixels of the window (fixed at 0) and finally the 8 pixels of the register (set at T = 65◦C) as shown in Figure 1. The picture in Figure 1 is displayed using the following MATLAB commands: plotT = T; % Copy the T array plotT(N+1,:) = 0; % Increase the number of rows by 1 plotT(:,N+1) = 0; % Increase the number of columns by 1 pcolor(1:N+1,1:N+1,plotT); % Plot it colorbar; Increasing the row andcolumns by 1 is necessary to get MATLAB to show the walls andthe window, otherwise only the interior of the room wouldshow. (d) Inside a while loop, the i,j’th cell gets it value from its neighbors, via an averaging relation of the form: T(i,j) = (oldT(i+1,j) + oldT(i-1,j) + oldT(i,j+1) + oldT(i,j-1))/4;
328 CHAPTER 11.PROGRAMMING IN MATLAB where oldT is the temperature array after the previous pass through the while loop.You have to program this in the appropriate place in the while loop and you have to make sure that you do not violate the boundaries of the array.You can use for loops to do this although it is much more efficient to use "slice indexing". (e)In the above averaging procedure,you may have overwritten some of the array that was meant to be fixed by the initial conditions,like the register,for instance. So,you had better make sure that you fix these up in the appropriate place before the while loop executes another pass. (f)The while loop is executed until the average change temperature changes less than 0.00001.The average change is calculated from: difference abs(T -oldT); change sum(sum(difference))/(N2); (Do a "help"on abs and sum to find out what these functions do.) (g)If you get everything correct,the final results look like Figure 2 which is plotted using the commands pcolor(1:N,1:N,T);shading interp;colorbar;. (h)Calculate and print out the average temperature and its variation: average sum(sum(T))/(N2); variation sum(sum(abs(T -average)))/(N2); For the above example,I got the average to be T-21.1514 while the variation was AT-5.39824.You should verify that you get this result before continuing. While this got the average temperature to within specifications,the variation is way out of spec.You have to do better.The easiest but most boring way to do it is to move the register around by typing in the configuration in the script M-file and running it again until you satisfy both the average and variation specifications. (BLIF's rule #197 of computer programming:Always do it the easy,boring way first!)In this case,however,you will need some intuition to get the answers to within specifications because there are many possibilities,both in the location of the register and its shape.You should have a look in your dorm or other rooms to see if you find any common relationships between placement of windows and heat registers.You should also hope that the architects and engineers thought about this carefully because the impact on heating costs and human comfort are quite large. Alternatively,you can try to find a way of automating the optimization procedure. How you do this is up to you!Be creative! Finally,Figure 3 shows a different starting position with the ending results shown in Figure 4.This is a terrible solution!Not only is the variation worse,but the register is so hot that you would burn yourself if you got close to it!
328 CHAPTER 11. PROGRAMMING IN MATLAB where oldT is the temperature array after the previous pass through the while loop. You have to program this in the appropriate place in the while loop andyou have to make sure that you do not violate the boundaries of the array. You can use for loops to do this although it is much more efficient to use “slice indexing”. (e) In the above averaging procedure, you may have overwritten some of the array that was meant to be fixedby the initial conditions, like the register, for instance. So, you hadbetter make sure that you fix these up in the appropriate place before the while loop executes another pass. (f) The while loop is executeduntil the average change temperature changes less than 0.00001. The average change is calculatedfrom: difference = abs(T - oldT); change = sum(sum(difference))/(N^2); (Do a “help” on abs and sum to findout what these functions do.) (g) If you get everything correct, the final results look like Figure 2 which is plotted using the commands pcolor(1:N,1:N,T); shading interp; colorbar;. (h) Calculate andprint out the average temperature andits variation: average = sum(sum(T))/(N^2); variation = sum(sum(abs(T - average)))/(N^2); For the above example, I got the average to be Tavg final = 21.1514 while the variation was ∆Tavg final = 5.39824. You shouldverify that you get this result before continuing. While this got the average temperature to within specifications, the variation is way out of spec. You have to do better. The easiest but most boring way to do it is to move the register aroundby typing in the configuration in the script M-file and running it again until you satisfy both the average andvariation specifications. (BLIF’s rule #197 of computer programming: Always do it the easy, boring way first!) In this case, however, you will needsome intuition to get the answers to within specifications because there are many possibilities, both in the location of the register andits shape. You shouldhave a look in your dorm or other rooms to see if you findany common relationships between placement of windows and heat registers. You shouldalso hope that the architects andengineers thought about this carefully because the impact on heating costs andhuman comfort are quite large. Alternatively, you can try to finda way of automating the optimization procedure. How you do this is up to you! Be creative! Finally, Figure 3 shows a different starting position with the ending results shown in Figure 4. This is a terrible solution! Not only is the variation worse, but the register is so hot that you wouldburn yourself if you got close to it!
11.10.PROJECTS 329 60 50 25 20 30 20 10 10 5 10 15 20 25 30 Figure 11.1:Typical starting condition for the 32x32 room with a register on the right wall atT=65°C
11.10. PROJECTS 329 0 10 20 30 40 50 60 5 10 15 20 25 30 5 10 15 20 25 30 Figure 11.1: Typical starting condition for the 32×32 room with a register on the right wall at T = 65◦C
330 CHAPTER 11.PROGRAMMING IN MATLAB 30 60 25 20 40 15 30 20 10 10 5 0 10 20 30 Figure 11.2:Final result for a 32x32 size room starting with the configuration of Figure 1. In this case,Tams =21.1514 and ATama =5.39824
330 CHAPTER 11. PROGRAMMING IN MATLAB 0 10 20 30 40 50 60 5 10 15 20 25 30 5 10 15 20 25 30 Figure 11.2: Final result for a 32×32 size room starting with the configuration of Figure 1. In this case, Tavg final = 21.1514 and∆Tavg final = 5.39824
11.10.PROJECTS 331 100 30 90 80 70 20 60 50 40 10 30 20 10 ☑☑☑☑☑☑☑☑☑☑☑☑☑☑☑☑☑☑ 0 5 10 15 20 25 30 Figure 11.3:Another starting condition for the 32x32 room with a register in one of the corners at T=105C
11.10. PROJECTS 331 0 10 20 30 40 50 60 70 80 90 100 5 10 15 20 25 30 5 10 15 20 25 30 Figure 11.3: Another starting condition for the 32×32 room with a register in one of the corners at T = 105◦C
332 CHAPTER 11.PROGRAMMING IN MATLAB 30 100 % 25 80 70 20 50 15 40 10 30 20 10 0 5 10 15 20 25 30 Figure 11.4:Final result for a 32x32 size room starting with the configuration of Figure 3. In this case,Tams=21.1643 and ATam =6.1069
332 CHAPTER 11. PROGRAMMING IN MATLAB 0 10 20 30 40 50 60 70 80 90 100 5 10 15 20 25 30 5 10 15 20 25 30 Figure 11.4: Final result for a 32×32 size room starting with the configuration of Figure 3. In this case, Tavg final = 21.1643 and∆Tavg final = 6.1069