2. Contents
1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
3 Script Development . . . . . . . . . . . . . . . . . . . . . . . . . . 2
3.1 GUI Design . . . . . . . . . . . . . . . . . . . . . . . . . . 2
3.2 Correcting Temperature Values . . . . . . . . . . . . . . . 4
3.3 Temperatures in the Hole . . . . . . . . . . . . . . . . . . 6
4 Completed Script . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
5 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6 Future Developments . . . . . . . . . . . . . . . . . . . . . . . . . 18
1 Summary
Designing this GUI was extremely challenging, and one of the most difficult
projects I did this year. The project s[ecification was to design a GUI that
would model the distribution of temperature across a plate in accordance with
Laplace’s equation, in an iterative process where the temperature at every arbi-
trary point on the plate was corrected to the mean of the four points immediatly
adjacent to it. The data used could either be a dataset specified by the user
or a default set. The code grew from the a program that used the default set
and allowed the user to only specify the spacing between the points and preci-
sion of the iterations to a full-fledged GUI that allowed the userr to change any
value and produce a series of charts to model this data. Designing a method to
correct the temperatures to the mean of the surrounding values in accordance
with Laplace’s equation was a diffcult puzzle that I eventually solved through a
series of complex matrix operations, in a method that produced corrected tem-
peratures quickly and efficiently, but only through a systematic series of lengthy
matrix operations. I also encountered a significant challenge in attempting to
code the behavior of the hole filled with conducting liquid in the centre of the
plate that is fixed at a temperature the average of all points around it, as it re-
peatedly encountered NaN errors and would not outpu any useful values. Both
these problems were resolved however, and I was able to program a GUI that
allows the user to input important variables, whether of their own choosing or
a default case, and produce a set of clear and informative graphs that modelled
the temperature distribution. Ultimately this resulted in a code that was an ef-
fective tool for the purpose it was designed, but could potentially receive further
development to increase user friendliness, aesthetics or allow the comparison of
several data sets in quick succession.
1
3. 2 Introduction
The purpose of this project was to write a MATLAB script that would model
the temperature distribution across a plate that was heated to a constant tem-
perature in the upper left corner and cooled to a constant temperature in the
bottom right, and had a hole containing a conductive liquid that ensured all
points in the hole are equal to the average of the temperatures surrounding the
hole. The script must therefore first define a matrix that represents the temper-
atures across the plate, estimate the initial temperatures of all the points on the
plate, and from that carry out an interative process to calculate each corrected
temperature, repeating the process until the error of the iteration drops below
a set level. The corrected temperature of each point is the average of the points
surrounding it on the plate. The project specified that the program must make
it possible to change every significant variable of the model, but also allow for
a default case, with the plate measuring 0.6 by 0.4 metres and a spacing of 0.01
metres between each point, heated to 100 degrees Kelvin 0.2 metres along the
upper left corner and cooled to 0 degrees Kelvin 0.1 metres along the bottom
right, the hole measuring 0.3 by 0.1 metres, the upper left corner of the hole
being situated 0.2 metres horizontally and vertically from the upper left of the
plate. The default iteration error level is 0.01. Therefore, I created a script
based on the special case defined in the brief, and then altered it into a more
general format, and created a GUI to act as a control panel for data input, with
the option of using a default dataset. The development cycle of the project is
given in the following section of this report.
3 Script Development
3.1 GUI Design
In designing the GUI itself I decided to forgo using Guide, therefore my project
is entirely programmatic, and I therefore took a great deal of information from
the Simple Programmatic GUI guide.[1] I felt a greater degree of control over the
program by coding everything myself, and I feared that I would not be able to
correctly use the uicontrol code proided by Guide. In retrospect I probably only
succeded in making work for myself, but I did gain a greater understandign and
appreciation of MATLAB. Initially, I set all values except the precision error
and spacing to the default values in the code and allowed the user to change the
value of both in the command line, using the same format as my first coding
project, the transmitted power of a pulley. All other values were defined in the
code in the appropriate point. The first two lines of code were therefore:
dx=input(’Input the desired spacing of points on the plate, in metres:’);
e=input(’Input the desired precision of the iterations:’);
I then coded a simple control panel GUI that allowed the user to change the
values of the spacing and precision through sliders, that worked between the
values of 0 and 0.1 metres in steps of 0.01 metres. I then changed the code to a
general case and added sliders for all variables, at this point a user had to close
the control panel after inputting the data, which created a filled contour plot.
I then learned how to code edit text boxes from the GUI Building guide.[2]
2
4. Figure 1: GUI Control Panel (sliders)
After doing so I replaced the sliders with edit boxes and added the ”Plot”
button, which automatically closes the control panel and activates the results
figures. I attempted to add axes to the control panel but the data would not
plot on the axes I defined in the figure.
3
5. Figure 2: GUI Control Panel (sliders)
3.2 Correcting Temperature Values
The main body of the program must define a matrix to contain the data cor-
responding to the temperatures across the plate, and then put that matrix
throgh an iterative process to find the corrected values. Defining the matrix
and special areas such as the plates and hole was fairly easy, since the coding
technique necessary to do so was given in the project specification. The main
problem was how to correct the temperatures in the matrix. I eventually de-
vised a method that is inelegant from a coding standpoint, but nonetheless
effective, when I looked at it as a matrix function and not a coding prob-
lem. I realised it was necessary to add the columns to the left and right
to each individual column, and to do the same with the rows. To explain
in more detail, it would be best to use an example; a simple 4 × 4 matrix.
M1 =
1 2 3 1
4 0 5 1
6 7 9 1
1 1 1 1
Let us consider only the value of point (2,2) on the matrixl which is 0.
According to the theory of the model, the corrected value will be equal to:
(2 + 4 + 5 + 7) ÷ 4 = 4.5 (1)
We must carry out a series of matrix operators. First, define a matrix that
contains the third column and any columns to the right of it, with the last two
columns being composed of zeroes, this has the effect of shifting the matrix two
spaces to the right.
M2 =
3 1 0 0
5 1 0 0
9 1 0 0
1 1 0 0
Then we add this new matrix to the original, and remove the last two
columns.
4
6. M3 =
4 3
9 1
15 8
2 2
This has the effect of adding adjacent columns together, the first column of
this matrix is the sum of the first and third columns of the original, and the
second column of this new matrix is the sum of the second and fourth columns
of the original. Then we repeat the process but with rows, taking the lowertwo
rows and moving them to the top of an empty 4 × 4 matrix, adding it to the
original and then removing the lower two rows, we find a new matrix where each
row is the sum of the row above and below it.
M4 =
7 9 12 2
5 1 6 2
These matrices do not have the same dimensions, but by removing the first
and last rows from the M3, and the first and last columns of M4, we find two
2 × 2 matrices that add to form:
M5 =
18 13
16 14
Divide each value by four, and you have a matrix that gives the corrected
values of the central four values in the matrix, if this matrix is used to replace
the centre of the original matrix, this has the effect of replacting every value
that is not part of the border of the matrix with it’s corrected value.
M6 =
1 2 3 1
4 4.5 3.25 1
6 4 3.5 1
1 1 1 1
The other values can be verified by inspection. This method is particularly
appropriate because it does not affect the values on the border of the matrix,
some of which are constants (the plates). In my program this method is used
to correct the values of the temperatures, they are then placed back into the
temperature matrix and the temperature of the walls and hole are altered ac-
cording to the demands of the problem. For example, a 1:10 scale of the default
model is transformed from:
temp old =
100.0000 100.0000 100.0000 50.0000 50.0000 25.0000 25.0000
100.0000 75.0000 75.0000 50.0000 50.0000 25.0000 25.0000
100.0000 75.0000 34.6875 34.6875 34.6875 34.6875 25.0000
50.0000 50.0000 34.6875 34.6875 34.6875 34.6875 0.0000
50.0000 50.0000 50.0000 25.0000 25.0000 0.0000 0.0000
into:
temp new =
100.0000 100.0000 100.0000 52.4219 39.9219 33.6719 25.0000
100.0000 87.5000 64.9219 52.4219 39.9219 33.6719 33.6719
100.0000 64.9219 37.0508 37.0508 37.0508 37.0508 29.8438
52.4219 52.4219 37.0508 37.0508 37.0508 37.0508 0.0000
50.0000 52.4219 42.3438 32.2656 32.2656 0.0000 0.0000
The low resolution of this matrix means it is slightly misleading, for instance
the corner values and some wall values seem inconsisent with the rules laid out
in the specification. It is important to note that these single points represent
what would be a large part of the array in the actual default case, but it does
serve as a moderately effective visual aid to the process.
5
7. 3.3 Temperatures in the Hole
The toughest technical challenge in designing this GUI was averaging the tem-
perature across the hole. Defining the section of the matrix that corresponds
to the hole was relatively easy. I first defined it for the default case as the area
between x arr=0.2 and 0.5, and between y arr=0.2 and 0.3, and after that was
able to convert it to the general case pretty easily. The code is designed to
convert the rows or columns of the matrix bordering the hole into vectors and
take an average of all the temperature values in these vectors, and then set the
temperature of the hole to that value. While using the default case, I noticed
that the vector ”l” which corresponds to the row immediately below the hole
was an empty vector. This resulted in the temperature of the hole being set to
a ”NaN” and a large area of the contour plot becoming white space, as shown
in Figure 3. For some reason, the code could not read the values of the matrix
between y arr=0.3 and 0.35. The problem seemingly fluctuated between lab
sessions- sometimes it would happen and sometime it would not, following the
conversion to the general case the problem seems to have disappeared, but I do
not know how or why.
Figure 3: Contour Plot due to NaN Error
6
8. 4 Completed Script
The basic operation of the script is that the user uses the control panel GUI
to enter the data into the script, then press the button marked ”Enter Data”,
shown below in Figure , or alternatively simply press the ”Default Data” but-
ton, thereby loading the default dataset. Pressing the ”Plot” button. Figure
shows the control panel with the appropriate data input needed to produce the
standard contour plot as defined in the project description, this closes the con-
trol panel and creates three additional Figures: a filled contour plot showing a
2D representation of the data, a mesh plot showing a 3D representation and a
text panel that gives the significant data of the model, as well as the number
of iterations required to complete the model. The colour axis of both graphs
is fixed with a maximum of 100 Kelvin and a minimum of 0 Kelvin, allowing
different datasets to be easily compared and instantly recognise the differences.
A step-by-step walkthrough of the code is shown below:
function the_answer=heat_distribution(dx,e)
% define control panel
f1=figure(’Position’,[500,200,1050,600],’Name’,’Control Panel’);
hdx=uicontrol(f1,’Style’,’edit’,’Position’,[800,300,100,50],
’callback’,{@spacing_Callback});
he=uicontrol(f1,’Style’,’edit’,’Position’,[800,200,100,50],
’callback’,{@precision_Callback});
hpw=uicontrol(f1,’Style’,’edit’,’Position’,[20,200,100,50],
’callback’,{@platewidth_Callback});
hpl=uicontrol(f1,’Style’,’edit’,’Position’,[20,300,100,50],
’callback’,{@platelength_Callback});
hhw=uicontrol(f1,’Style’,’edit’,’Position’,[20,400,100,50],
’callback’,{@holewidth_Callback});
hhl=uicontrol(f1,’Style’,’edit’,’Position’,[20,500,100,50],
’callback’,{@holelength_Callback});
hhx=uicontrol(f1,’Style’,’edit’,’Position’,[400,400,100,50],
’callback’,{@holexcoordinate_Callback});
hhy=uicontrol(f1,’Style’,’edit’,’Position’,[400,500,100,50],
’callback’,{@holeycoordinate_Callback});
htemp1=uicontrol(f1,’Style’,’edit’,’Position’,[400,300,100,50],
’callback’,{@heatedtemp_Callback});
htemp2=uicontrol(f1,’Style’,’edit’,’Position’,[400,200,100,50],
’callback’,{@cooledtemp_Callback});
htemp1d=uicontrol(f1,’Style’,’edit’,’Position’,[800,400,100,50],
’callback’,{@heateddimensions_Callback});
htemp2d=uicontrol(f1,’Style’,’edit’,’Position’,[800,500,100,50],
’callback’,{@cooleddimensions_Callback});
henter=uicontrol(f1,’Style’,’pushbutton’,’String’,’Enter Data’,
’Position’,[20,100,100,50]);
hdefault=uicontrol(f1,’Style’,’pushbutton’,’String’,’Default Data’,
’Position’,[900,100,100,50],’callback’,{@defaultbutton_Callback});
hplot=uicontrol(f1,’Style’,’pushbutton’,’String’,’Plot’,
’Position’,[420,100,100,50],’callback’,{@plotbutton_Callback});
7
9. st1=uicontrol(f1,’Style’,’text’,’String’,’Spacing
(default 0.01 metres)’,’Position’,[900,300,100,40]);
st2=uicontrol(f1,’Style’,’text’,’String’,’Iteration Precision
(default 0.01)’,’Position’,[900,200,100,40]);
st3=uicontrol(f1,’Style’,’text’,’String’,’Plate Width (default 0.6 metres)’,
’Position’,[120,200,100,40]);
st4=uicontrol(f1,’Style’,’text’,’String’,’Plate Height (default 0.4 metres)’
,’Position’,[120,300,100,40]);
st5=uicontrol(f1,’Style’,’text’,’String’,’Hole Width (default 0.3 metres)’,
’Position’,[120,400,100,40]);
st6=uicontrol(f1,’Style’,’text’,’String’,’Hole Height (default 0.1 metres)’,
’Position’,[120,500,100,40]);
st7=uicontrol(f1,’Style’,’text’,’String’,’Hole Horizontal Position
(default 0.2 metres)’,’Position’,[500,400,100,40]);
st8=uicontrol(f1,’Style’,’text’,’String’,’Heated Temperature
(default 100 Kelvin)’,’Position’,[500,300,100,40]);
st9=uicontrol(f1,’Style’,’text’,’String’,’Cooled Temperature
(default 0 Kelvin)’,’Position’,[500,200,100,40]);
st10=uicontrol(f1,’Style’,’text’,’String’,’Heated Plate Dimensions
(default 0.2 metres)’,’Position’,[900,400,100,40]);
st11=uicontrol(f1,’Style’,’text’,’String’,’Cooled Plate Dimensions
(default 0.1 metres)’,’Position’,[900,500,100,40]);
st12=uicontrol(f1,’Style’,’text’,’String’,’Hole Vertical Position
(default 0.2 metres)’,’Position’,[500,500,100,40]);
This section began the function, created the figure of the control panel (f1)
and defined the positions and sizes of the enter text boxes and attendant labels,
and the push buttons that allow the data to be entered and plotted
%input non-default data
waitfor (hdx,’value’)
function spacing_Callback(hdx,event)
dx=str2double(get(hdx,’string’));
end
waitfor (hpw,’value’)
function platewidth_Callback(hpw,event)
pw=str2double(get(hpw,’string’));
end
waitfor (hpl,’value’)
function platelength_Callback(hpl,event)
pl=str2double(get(hpl,’string’));
end
waitfor (htemp1,’value’)
function heatedtemp_Callback(htemp1,event)
temp1=str2double(get(htemp1,’string’));
end
8
10. waitfor (htemp1d,’value’)
function heateddimensions_Callback(htemp1d,event)
temp1d=str2double(get(htemp1d,’string’));
end
waitfor (htemp2,’value’)
function cooledtemp_Callback(htemp2,event)
temp2=str2double(get(htemp2,’string’));
end
waitfor (htemp2d,’value’)
function cooleddimensions_Callback(htemp2d,event)
temp2d=str2double(get(htemp2d,’string’));
end
waitfor (hhw,’value’)
function holewidth_Callback(hhw,event)
hw=str2double(get(hhw,’string’));
end
waitfor (hhl,’value’)
function holelength_Callback(hhl,event)
hl=str2double(get(hhl,’string’));
end
waitfor (hhx,’value’)
function holexcoordinate_Callback(hhx,event)
hx=str2double(get(hhx,’string’));
end
waitfor (hhy,’value’)
function holeycoordinate_Callback(hhy,event)
hy=str2double(get(hhy,’string’));
end
waitfor (he,’value’)
function precision_Callback(he,event)
e=str2double(get(he,’string’));
end
% define default dataset
function defaultbutton_Callback(hdefault,event)
dx=0.01;
e=0.01;
pw=0.6;
pl=0.4;
hw=0.3;
hl=0.1;
hx=0.2;
hy=0.2;
9
11. temp1=100;
temp2=0;
temp1d=0.2;
temp2d=0.1;
end
waitfor(henter,’ButtonDownFcn’)
This section codes the behavior of the edit boxes, the ”waitfor” preceding
each nested function ensures that the code waits for the value of the editbox
to change, after which the nested function extracts the value and the output of
each edit box is assigned a handle, corresponding to a variable in the model.
The control panel is designed so that each edit box is labelled appropriately and
indicates which variable it corresponds to. The ”waitfor” also ensures that the
latest value is used if the values are changed, and prevents NaN being entered for
any variable. It also codes the ”Default Data” button, it defines the default data
set and ensures it only activates if the ”Default Data” button is pressed. The
”waitfor(henter,’ButtonDownFcn’)” ensures that the variables are not enetered
unless the ”Enter Data” button is pressed.
%produce_matrix
format short
x=0:dx:pw;
y=0:dx:pl;
nx = length(x);
ny = length(y);
[x_arr, y_arr] = meshgrid(x, y);
temp = zeros(ny,nx);
% set heated points
heated_top = find((x_arr <= temp1d) & (y_arr == 0));
heated_left = find((x_arr == 0) & (y_arr <=temp1d));
heated_points=union(heated_top,heated_left);
temp(heated_points)=temp1;
%set cooled points
cooled_bottom=find((x_arr>=pw-temp2d)&(x_arr<=pw)&(y_arr==pl));
cooled_right=find((x_arr==pw)&(y_arr>=pl-temp2d));
cooled_points=union(cooled_bottom,cooled_right);
temp(cooled_points)=temp2;
This are of code begins to construct the matrix representing temperature,
creating an empty matrix of equal dimesnions to the plate and defining the
lengths and temperatures of the constantly heated and cooled regions. It does
this by using the variables pl (plate length), pw (plate width), dx (point spacing),
temp1 (constant hot temperature), temp2 (constant cold temperature), temp1d
(lengh of hot plate) and temp2d (length of cold plate). It is copied from or
extrapolates on the code given in the project specification for this purpose. [3]
temp3=0.5*(temp1+temp2);
10
13. jt=mean(j);
k=temp((x_arr==pw-dx)&(y_arr>=hy-hl)&(y_arr<=hy));
kt=mean(k);
l=temp((x_arr>=hx)&(x_arr<=hx+hw)&(y_arr>hy+hl)&(y_arr<=hy+hl+dx));
lt=mean(l);
h=(it+jt+kt+lt)/4;
temp(hole)=h;
This section completes the initial assumptions of the plate temperatures.
The first block of code define the temperatures of the walls as equal to the
temperatures of the points immediately adjacent to them in the plate proper,
with the temperature of the two corners that are not part of the heating plates
being defined as the temperature of the point immedately above (bottom left)
or below (top right) them on the walls. The temperature of the hole was a
technical challenge, as previously mentioned, but has been mostly fixed, the
second block defines the points that make up the hole, and defines the rows or
columns bordering them. These four vectors: it, jt, kt and lt are all averaged,
the averages are averaged to a single number h, which is then given as the
temperature of the hole. Figure 4 is an example of what a contour plot using
this data would look like (default data).
Figure 4: Initial Temperature Contour Plot
12
15. n=temp1-temp2;
ite=0;
This section of the code averages the temperatures in the ”center” of the
plate, namely every area that is not the walls, the process by which the tem-
peratures were averaged has been explored in detail in the previous section.
After averaging the center, the handle of the matrix is changed to ”temp old”
in preparation for the interative process, and then the walls and hole have their
temperatures changed to accomodate their specific properties. It also defines
a new matrix, ”temp new”, also in preparation for the iterative process, and
also provides it with the heated and cooled plates. It defines n, the number of
contour lines in the final contour plot as the difference between the two tem-
peratures, and gives the initial value of ”ite” as zero. ”ite” is the number of
iterations before the difference at each iteration is less than the precision level.
while abs(temp_old(2,2)-((temp_old(2,1)+temp_old(2,3)+
temp_old(3,2)+temp_old(1,2))/4))>e;
ite=ite+1;
R=zeros(1,nx);
S=zeros(ny,1);
M=temp_old(:,3:nx);
N=[M S S];
T1=temp_old+N;
T1=T1(:,1:nx-2);
T1=T1(2:ny-1,:);
O=temp_old(3:ny,:);
P=[O;R;R];
T2=temp_old+P;
T2=T2(1:ny-2,:);
T2=T2(:,2:nx-1);
T=(T1+T2)/4;
centre=find((x_arr>0)&(x_arr<pw)&(y_arr>0)&(y_arr<pl));
temp_new(centre)=T;
heated_top = find((x_arr <= temp1d) & (y_arr == 0));
heated_left = find((x_arr == 0) & (y_arr <=temp1d));
heated_points=union(heated_top,heated_left);
temp_new(heated_points)=temp1;
cooled_bottom=find((x_arr>=pw-temp2d)&(x_arr<=pw)&(y_arr==pl));
cooled_right=find((x_arr==pw)&(y_arr>=pl-temp2d));
cooled_points=union(cooled_bottom,cooled_right);
temp_new(cooled_points)=temp2;
left_wall=find((x_arr==0)&(y_arr>temp1d)&(y_arr<pl));
temp_new(left_wall)=temp((x_arr==dx)&(y_arr>temp1d)&(y_arr<pl));
temp_new((x_arr==0)&(y_arr==pl))=temp((x_arr==0)&(y_arr==pl-dx));
right_wall=find((x_arr==pw)&(y_arr<pl-temp2d)&(y_arr>=dx));
temp_new(right_wall)=temp((x_arr==pw-dx)&(y_arr<pl-temp2d)&(y_arr>=dx));
temp_new((x_arr==0.6)&(y_arr==0))=temp((x_arr==pw)&(y_arr==dx));
floor=find((x_arr>0)&(x_arr<pw-temp2d)&(y_arr==pl));
14
17. Figure 5: Unmanipulated Temperature Contour Plot
function plotbutton_Callback(hplot,event)
close(f1)
end
f2=figure(’Position’,[0,100,1000,800],’Name’,’Contour Plot’);
ha=axes(’Units’,’Pixels’);
contourf(ha,Z,n);
caxis([0 100]);
colorbar;
axis off;
f3=figure(’Position’,[950,500,500,500],’Name’,’Important Data’);
st13=uicontrol(f3,’Style’,’text’,’String’,[’Spacing between adjacent points is ’,
num2str(dx),’ metres’],’Position’,[50 25 400 50],’FontSize’,12,’FontWeight’,’bold’);
st14=uicontrol(f3,’Style’,’text’,’String’,[’Iteration precision (error level) is ’,
num2str(e)],’Position’,[50 75 400 50],’FontSize’,12,’FontWeight’,’bold’);
st15=uicontrol(f3,’Style’,’text’,’String’,[’Plate dimensions are ’,num2str(pw),’ x ’,
num2str(pl),’ metres’],’Position’,[50 125 400 50],’FontSize’,12,’FontWeight’,’bold’);
st16=uicontrol(f3,’Style’,’text’,’String’,[’Hole dimensions are ’,num2str(hw),’ x ’,
num2str(hl),’ metres’],’Position’,[50 175 400 50],’FontSize’,12,’FontWeight’,’bold’);
st17=uicontrol(f3,’Style’,’text’,’String’,[’The top left corner of the hole is ’,
num2str(hx),’ to the right and ’,num2str(hy),’ metres below the top left corner of the pla
16
18. st18=uicontrol(f3,’Style’,’text’,’String’,[’The temperatures range from ’,num2str(temp2),’
num2str(temp1),’ degrees Kelvin’],’Position’,[50 275 400 50],’FontSize’,12,’FontWeight’,’b
st19=uicontrol(f3,’Style’,’text’,’String’,[’The heated plate measures ’,num2str(temp1d),
’ metres to a side’],’Position’,[50 325 400 50],’FontSize’,12,’FontWeight’,’bold’);
st20=uicontrol(f3,’Style’,’text’,’String’,[’The cooled plate measures ’,num2str(temp2d),,’
st21=uicontrol(f3,’Style’,’text’,’String’,[’The process is completed in ’,num2str(ite),
’ iterations’],’Position’,[50 425 400 50],’FontSize’,12,’FontWeight’,’bold’);
f4=figure(’Position’,[1400,100,500,500],’Name’,’Mesh Plot’);
graphwidth=(pw/dx)+1;
graphlength=(pl/dx)+1;
mesh(Z);
axis([1 graphwidth 1 graphlength]);
caxis([0 100]);
colorbar;
end
Finally, pressing the ”Plot” button on the control panel closes it, creating
three new Figures: a filled contour plot, a text window detailing the variables
of the model and a mesh plot showing a 3D representation of the data. The
axes of the meshplot are defined as the number of points that make up the x or
y axis, calculated as the plate dimenosions divided by the spacing and with an
additional , as to prevent unwanted white space. The process is now complete.
Figure 6: Results of Program
Although I feel the code has been completed to a competent standard, there
are changes and additions that I would have made, and would like to make at
some point in the future, if I had more time and greater programming skill,
those are laid out in the next two sections.
17
19. 5 Discussion
I believe that my code was completed to a satisfactory standard and fulfils the
project specification, allowing a user to model the distribution of temperature
across a plate, using either a default case or values of their own choosing for
the important variables. However, I recognise that it could still be improved.
The scope is limited and does not allow for quick changes of the data. It
should also be noted that if the spacing between the points on the plate is
small in comparison to the dimensions of the plate, then the code takes a great
deal of time to complete and may possibly suffer an NaN error, but this is
rare. I could not find a way to cause the graph to output to an axes on the
control panel, meaning it is necessary to close the control panel and restart
the program if you wish to compare two separate data sets. The method of
correcting the temperature values is effective and relatively quick if the spacing
and iteration precision of the data is not very small in comparison to the other
values, but is not the most elegant solution from a coding standpoint, and relies
on brute-forcing the mathematics rather than correcting each value one by one,
such as in a Kernel program. The charts are clear, aesthetically pleasing and
informative, and use a broad range of the capabilities of MATLAB, displaying
the data graphically and verbally. In short, the finished project is competently
made, and a useful tool, but it is not perfect and there is still room for further
developments.
6 Future Developments
I would like to add some animation to the GUI, to improve user friendliness and
aesthetic appeal to the user, ideally I would like to show how the contour lines
move and change as the model becomes increasingly close to reality. A small
change that would prevent NaN errors would be to cause the GUI to reject any
values of spacing lower than the values for the shortest plate dimension by a
factor of 100. Another possible addition to the project that I did not have time
to develop, as the idea only occured shortly before the deadline, would be a
single scatter graph to show how the temperature varies along a diagonal line
across the plate from the upper left to bottom right corners. Finally, I would
have liked to have included the graphs on the control panel, which change with
the data, allowing quick and easy comparison of myriad data sets, but ultimately
this was a coding puzzle that I could not solve.
[1] [2] [3]
18
20. Bibliography
[1] MATLAB Help. About the simple programmatic gui, 2012.
[2] MATLAB Help. Gui building/component selection/gui controls and indica-
tors/uicontrol, 2012.
[3] Dr Andrew Lawrie. Computer-based modelling: Matlab projects, 2014.
19