Comparing Finite difference method answer with analytical for 2d plate heat transfer

56 views (last 30 days)
I need to calculate the temperature distrubtion over time of a 2D aluminium plate until thermal equalibrium is reached.
temperature calculations are based on the explicit finite difference method, calculations will be done considering the region of interest covered by a uniform grid. The plate will be split up into a grid, user inputs their grid spacing requirment.
matrices will be used to show the temperature changes
initial matrix will be plate at start of calculations all filled with 0's except for boundary conditions.
The matrices created using FDM then needs to be compared with a matrices created using an analytical solution (formula added)
I have the code for the FDM matrix and graph but struggling to correctly enter the code for the analytical solution to be able to compare the 2.
Any help is much appreciated
clc %% CLear Command Window
clear %% Clear Variables from code
close all %% Close all figure windows
%--------------------------------------------------------------------------------------------------------------------------%
% Define values for code
x=6; %% X Variable equal to
y=6; %% Y Variable equal to
k= 143; %% Conductivity of Aluminium
p= 2.8*10^3; %% Density value
c= 795; %% Specific heat value
alpha= k/(p*c); %% Calculate Alpha using above values
%--------------------------------------------------------------------------------------------------------------------------%
% User enters their grid spacing
%h=input('Enter your material grid spaceing here - '); %% User enters their grid spaceing
h=0.1;
while mod(6, h) ~= 0 || h<0 || h>=6 %% Check is users grid spacing is valid by checking divisible into 6
fprintf('Your grid spacing is not valid \n'); %% If grid spaceing entered is not valid tell user
h=input('Enter your material grid spaceing here - ');
end
%--------------------------------------------------------------------------------------------------------------------------%
% Calculate Matrix dimensions
rows= (y/h)+1; %% Matrix rows is x(sheet width) / user input for h
columns= (x/h)+1; %% Matrix columns is y(Sheet Length) / user input h
%--------------------------------------------------------------------------------------------------------------------------%
%% Initialise Matrix
T=zeros(rows,columns); %% T is Matrix, filled with zeros until conditions are determined
%--------------------------------------------------------------------------------------------------------------------------%
%% Ammend Matrix with boundary conditions
for c=1:columns
d=(c-1)*h; %% Variable 'd' is equal to c-1*user grid spacing
if d<=2/3*x %% If variable 'd' is less than or equal to 2/3 of x complete following formula
T(1,c)=12.5*d;
else %% If variable 'd' is greater than or equal to 2/3 of x complete following formula
T(1,c)= -25*d+150;
end
end
%--------------------------------------------------------------------------------------------------------------------------%
% User enters their time step value, this gets checked to ensure its valid
%dt=input('Enter your time step here - '); %% User enters their time step here
dt=0.1*h^2/alpha;
Fo= (alpha*dt)/(h^2); %% Calculation for Fouriers Number
while Fo<0 || Fo>0.25
fprintf('Your time step is not valid \n'); %% If time step entered is not valid tell user
dt=input('Enter your time step here - ');
end
%--------------------------------------------------------------------------------------------------------------------------%
% Creating Further Matrices
max_change_threshold = 0.01; %% Maximum change allowed for equilibrium, Change this value as needed
time = 0; %% Initialize time
while true %% Iterate until thermal equilibrium is reached
T_new = T;
for i = 2:(rows-1) %% Calculate new temperatures for interior points
for j = 2:(columns-1)
T_new(i,j) = T(i,j) + Fo*(T(i+1,j) + T(i-1,j) + T(i,j+1) + T(i,j-1) - 4*T(i,j));
end
end
%--------------------------------------------------------------------------------------------------------------------------%
% Check for thermal equilibrium
max_change = max(abs(T_new - T),[],"all");
if max_change < max_change_threshold
% Exit loop if thermal equilibrium is reached
break;
end
% Update the temperature matrix and time for the next iteration
T = T_new;
time = time + dt;
end
fprintf('Thermal equilibrium reached at time = %f seconds\n', time); % Display Thermal equilibrium message has been reached to user
Thermal equilibrium reached at time = 12344.181818 seconds
fprintf('Temperature from Numerical Solution = \n%T')
Temperature from Numerical Solution =
disp(T)
Columns 1 through 19 0 1.2500 2.5000 3.7500 5.0000 6.2500 7.5000 8.7500 10.0000 11.2500 12.5000 13.7500 15.0000 16.2500 17.5000 18.7500 20.0000 21.2500 22.5000 0 1.1709 2.3417 3.5126 4.6835 5.8543 7.0251 8.1959 9.3667 10.5374 11.7080 12.8786 14.0491 15.2194 16.3896 17.5596 18.7293 19.8987 21.0676 0 1.0922 2.1845 3.2767 4.3689 5.4611 6.5532 7.6453 8.7373 9.8293 10.9211 12.0127 13.1042 14.1954 15.2863 16.3767 17.4667 18.5559 19.6444 0 1.0146 2.0292 3.0438 4.0583 5.0728 6.0873 7.1016 8.1159 9.1300 10.1440 11.1577 12.1712 13.1843 14.1969 15.2088 16.2201 17.2303 18.2393 0 0.9384 1.8768 2.8152 3.7535 4.6918 5.6300 6.5682 7.5061 8.4440 9.3815 10.3188 11.2558 12.1922 13.1280 14.0630 14.9971 15.9299 16.8611 0 0.8641 1.7282 2.5923 3.4564 4.3203 5.1842 6.0480 6.9116 7.7750 8.6381 9.5009 10.3632 11.2250 12.0860 12.9460 13.8049 14.6623 15.5178 0 0.7921 1.5843 2.3764 3.1684 3.9604 4.7523 5.5440 6.3355 7.1268 7.9178 8.7084 9.4985 10.2879 11.0765 11.8640 12.6502 13.4346 14.2169 0 0.7228 1.4457 2.1684 2.8912 3.6138 4.3363 5.0587 5.7809 6.5028 7.2244 7.9455 8.6661 9.3859 10.1048 10.8225 11.5387 12.2531 12.9651 0 0.6565 1.3130 1.9695 2.6259 3.2822 3.9384 4.5944 5.2503 5.9058 6.5609 7.2156 7.8697 8.5230 9.1753 9.8263 10.4758 11.1233 11.7682 0 0.5935 1.1869 1.7803 2.3737 2.9669 3.5601 4.1530 4.7457 5.3382 5.9302 6.5218 7.1127 7.7027 8.2918 8.8795 9.4656 10.0497 10.6311 0 0.5339 1.0678 1.6016 2.1354 2.6691 3.2026 3.7360 4.2691 4.8019 5.3344 5.8663 6.3976 6.9280 7.4573 7.9854 8.5117 9.0360 9.5576 0 0.4780 0.9559 1.4338 1.9117 2.3894 2.8670 3.3445 3.8217 4.2985 4.7750 5.2510 5.7263 6.2008 6.6742 7.1462 7.6166 8.0849 8.5506 0 0.4258 0.8516 1.2773 1.7029 2.1285 2.5539 2.9792 3.4042 3.8289 4.2532 4.6770 5.1002 5.5225 5.9438 6.3637 6.7820 7.1983 7.6119 0 0.3774 0.7548 1.1322 1.5094 1.8866 2.2637 2.6406 3.0172 3.3936 3.7695 4.1450 4.5198 4.8938 5.2668 5.6385 6.0087 6.3768 6.7425 0 0.3328 0.6657 0.9984 1.3312 1.6638 1.9963 2.3286 2.6607 2.9925 3.3240 3.6549 3.9853 4.3148 4.6434 4.9708 5.2966 5.6206 5.9421 0 0.2920 0.5841 0.8760 1.1679 1.4598 1.7515 2.0430 2.3344 2.6254 2.9161 3.2063 3.4960 3.7849 4.0729 4.3597 4.6451 4.9287 5.2101 0 0.2549 0.5098 0.7647 1.0195 1.2742 1.5288 1.7832 2.0375 2.2915 2.5451 2.7983 3.0510 3.3030 3.5541 3.8041 4.0528 4.2998 4.5448 0 0.2214 0.4427 0.6640 0.8852 1.1064 1.3275 1.5484 1.7691 1.9896 2.2097 2.4295 2.6488 2.8674 3.0852 3.3020 3.5176 3.7316 3.9438 0 0.1912 0.3824 0.5735 0.7646 0.9557 1.1466 1.3374 1.5280 1.7184 1.9085 2.0982 2.2875 2.4762 2.6641 2.8512 3.0371 3.2216 3.4044 0 0.1643 0.3285 0.4928 0.6570 0.8211 0.9851 1.1490 1.3128 1.4763 1.6396 1.8026 1.9651 2.1271 2.2884 2.4489 2.6083 2.7666 2.9232 0 0.1404 0.2808 0.4211 0.5615 0.7017 0.8419 0.9820 1.1219 1.2616 1.4011 1.5403 1.6791 1.8174 1.9552 2.0922 2.2282 2.3632 2.4967 0 0.1193 0.2387 0.3580 0.4773 0.5965 0.7156 0.8347 0.9536 1.0723 1.1909 1.3091 1.4271 1.5445 1.6615 1.7778 1.8933 2.0078 2.1211 0 0.1009 0.2018 0.3027 0.4035 0.5043 0.6050 0.7056 0.8062 0.9065 1.0067 1.1066 1.2063 1.3055 1.4043 1.5025 1.6000 1.6966 1.7922 0 0.0848 0.1697 0.2545 0.3393 0.4240 0.5087 0.5933 0.6778 0.7622 0.8464 0.9304 1.0141 1.0975 1.1805 1.2630 1.3448 1.4259 1.5061 0 0.0709 0.1419 0.2128 0.2837 0.3546 0.4254 0.4961 0.5668 0.6373 0.7077 0.7779 0.8479 0.9176 0.9869 1.0558 1.1242 1.1919 1.2588 0 0.0590 0.1180 0.1770 0.2360 0.2949 0.3538 0.4126 0.4713 0.5300 0.5885 0.6469 0.7050 0.7630 0.8206 0.8778 0.9346 0.9908 1.0463 0 0.0488 0.0976 0.1464 0.1951 0.2439 0.2926 0.3412 0.3898 0.4383 0.4867 0.5349 0.5830 0.6309 0.6785 0.7258 0.7727 0.8191 0.8649 0 0.0401 0.0803 0.1204 0.1605 0.2006 0.2406 0.2806 0.3206 0.3605 0.4002 0.4399 0.4794 0.5188 0.5579 0.5968 0.6353 0.6734 0.7110 0 0.0328 0.0656 0.0985 0.1313 0.1640 0.1968 0.2295 0.2622 0.2948 0.3273 0.3597 0.3921 0.4242 0.4562 0.4879 0.5194 0.5505 0.5813 0 0.0267 0.0534 0.0801 0.1068 0.1334 0.1600 0.1866 0.2132 0.2397 0.2662 0.2925 0.3188 0.3449 0.3709 0.3967 0.4223 0.4476 0.4725 0 0.0216 0.0432 0.0648 0.0863 0.1079 0.1294 0.1509 0.1724 0.1939 0.2152 0.2366 0.2578 0.2789 0.2999 0.3208 0.3414 0.3618 0.3820 0 0.0174 0.0347 0.0521 0.0694 0.0868 0.1041 0.1214 0.1386 0.1559 0.1731 0.1902 0.2073 0.2242 0.2411 0.2579 0.2745 0.2909 0.3070 0 0.0139 0.0278 0.0416 0.0555 0.0694 0.0832 0.0970 0.1109 0.1246 0.1384 0.1521 0.1657 0.1793 0.1928 0.2061 0.2194 0.2325 0.2454 0 0.0110 0.0221 0.0331 0.0441 0.0552 0.0662 0.0772 0.0881 0.0991 0.1100 0.1209 0.1317 0.1425 0.1532 0.1639 0.1744 0.1848 0.1950 0 0.0087 0.0174 0.0262 0.0349 0.0436 0.0523 0.0610 0.0697 0.0783 0.0870 0.0956 0.1041 0.1126 0.1211 0.1295 0.1378 0.1460 0.1541 0 0.0069 0.0137 0.0206 0.0274 0.0343 0.0411 0.0479 0.0548 0.0616 0.0683 0.0751 0.0818 0.0885 0.0952 0.1018 0.1083 0.1147 0.1211 0 0.0054 0.0107 0.0161 0.0214 0.0268 0.0321 0.0375 0.0428 0.0481 0.0534 0.0587 0.0639 0.0692 0.0744 0.0795 0.0846 0.0896 0.0946 0 0.0042 0.0083 0.0125 0.0167 0.0208 0.0250 0.0291 0.0332 0.0374 0.0415 0.0456 0.0497 0.0537 0.0578 0.0618 0.0657 0.0696 0.0735 0 0.0032 0.0064 0.0096 0.0129 0.0161 0.0193 0.0225 0.0257 0.0289 0.0321 0.0352 0.0384 0.0415 0.0446 0.0477 0.0508 0.0538 0.0568 0 0.0025 0.0049 0.0074 0.0099 0.0123 0.0148 0.0173 0.0197 0.0222 0.0246 0.0270 0.0295 0.0319 0.0343 0.0366 0.0390 0.0413 0.0436 0 0.0019 0.0038 0.0057 0.0075 0.0094 0.0113 0.0132 0.0151 0.0169 0.0188 0.0207 0.0225 0.0243 0.0262 0.0280 0.0298 0.0315 0.0333 0 0.0014 0.0029 0.0043 0.0057 0.0072 0.0086 0.0100 0.0114 0.0129 0.0143 0.0157 0.0171 0.0185 0.0199 0.0212 0.0226 0.0239 0.0253 0 0.0011 0.0022 0.0032 0.0043 0.0054 0.0065 0.0076 0.0086 0.0097 0.0108 0.0118 0.0129 0.0139 0.0150 0.0160 0.0170 0.0181 0.0191 0 0.0008 0.0016 0.0024 0.0032 0.0041 0.0049 0.0057 0.0065 0.0073 0.0081 0.0089 0.0097 0.0105 0.0112 0.0120 0.0128 0.0135 0.0143 0 0.0006 0.0012 0.0018 0.0024 0.0030 0.0036 0.0042 0.0048 0.0054 0.0060 0.0066 0.0072 0.0078 0.0084 0.0090 0.0095 0.0101 0.0107 0 0.0004 0.0009 0.0013 0.0018 0.0022 0.0027 0.0031 0.0036 0.0040 0.0045 0.0049 0.0054 0.0058 0.0062 0.0067 0.0071 0.0075 0.0079 0 0.0003 0.0007 0.0010 0.0013 0.0017 0.0020 0.0023 0.0026 0.0030 0.0033 0.0036 0.0039 0.0043 0.0046 0.0049 0.0052 0.0055 0.0058 0 0.0002 0.0005 0.0007 0.0010 0.0012 0.0015 0.0017 0.0019 0.0022 0.0024 0.0027 0.0029 0.0031 0.0034 0.0036 0.0038 0.0040 0.0043 0 0.0002 0.0004 0.0005 0.0007 0.0009 0.0011 0.0012 0.0014 0.0016 0.0018 0.0019 0.0021 0.0023 0.0024 0.0026 0.0028 0.0030 0.0031 0 0.0001 0.0003 0.0004 0.0005 0.0006 0.0008 0.0009 0.0010 0.0011 0.0013 0.0014 0.0015 0.0017 0.0018 0.0019 0.0020 0.0021 0.0023 0 0.0001 0.0002 0.0003 0.0004 0.0005 0.0006 0.0006 0.0007 0.0008 0.0009 0.0010 0.0011 0.0012 0.0013 0.0014 0.0015 0.0015 0.0016 0 0.0001 0.0001 0.0002 0.0003 0.0003 0.0004 0.0005 0.0005 0.0006 0.0007 0.0007 0.0008 0.0009 0.0009 0.0010 0.0010 0.0011 0.0012 0 0.0000 0.0001 0.0001 0.0002 0.0002 0.0003 0.0003 0.0004 0.0004 0.0005 0.0005 0.0006 0.0006 0.0007 0.0007 0.0007 0.0008 0.0008 0 0.0000 0.0001 0.0001 0.0001 0.0002 0.0002 0.0002 0.0003 0.0003 0.0003 0.0004 0.0004 0.0004 0.0005 0.0005 0.0005 0.0006 0.0006 0 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0002 0.0002 0.0002 0.0002 0.0003 0.0003 0.0003 0.0003 0.0003 0.0004 0.0004 0.0004 0 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0002 0.0002 0.0002 0.0002 0.0002 0.0002 0.0003 0.0003 0.0003 0 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0002 0.0002 0.0002 0.0002 0.0002 0 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 20 through 38 23.7500 25.0000 26.2500 27.5000 28.7500 30.0000 31.2500 32.5000 33.7500 35.0000 36.2500 37.5000 38.7500 40.0000 41.2500 42.5000 43.7500 45.0000 46.2500 22.2360 23.4037 24.5706 25.7364 26.9009 28.0638 29.2246 30.3827 31.5376 32.6884 33.8339 34.9727 36.1029 37.2218 38.3255 39.4087 40.4628 41.4740 42.4177 20.7318 21.8178 22.9022 23.9845 25.0642 26.1407 27.2131 28.2804 29.3413 30.3942 31.4370 32.4668 33.4799 34.4715 35.4346 36.3595 37.2315 38.0285 38.7144 19.2468 20.2523 21.2555 22.2555 23.2519 24.2435 25.2292 26.2075 27.1767 28.1344 29.0776 30.0024 30.9039 31.7753 32.6078 33.3889 34.1012 34.7197 35.2082 17.7903 18.7171 19.6407 20.5605 21.4754 22.3843 23.2858 24.1780 25.0586 25.9248 26.7729 27.5984 28.3953 29.1559 29.8704 30.5252 31.1027 31.5791 31.9228 16.3709 17.2211 18.0676 18.9094 19.7456 20.5747 21.3950 22.2045 23.0005 23.7797 24.5383 25.2710 25.9717 26.6321 27.2421 27.7886 28.2552 28.6209 28.8602 14.9965 15.7728 16.5449 17.3118 18.0723 18.8249 19.5678 20.2985 21.0144 21.7120 22.3871 23.0344 23.6475 24.2185 24.7375 25.1925 25.5689 25.8493 26.0137 13.6742 14.3796 15.0806 15.7759 16.4643 17.1441 17.8135 18.4701 19.1109 19.7324 20.3305 20.8998 21.4343 21.9263 22.3668 22.7451 23.0488 23.2636 23.3742 12.4101 13.0481 13.6814 14.3087 14.9289 15.5401 16.1404 16.7275 17.2984 17.8497 18.3773 18.8761 19.3404 19.7632 20.1364 20.4508 20.6959 20.8604 20.9323 11.2094 11.7836 12.3530 12.9163 13.4723 14.0192 14.5551 15.0776 15.5840 16.0709 16.5344 16.9698 17.3719 17.7344 18.0502 18.3114 18.5094 18.6350 18.6792 10.0760 10.5904 11.0999 11.6033 12.0993 12.5863 13.0624 13.5254 13.9726 14.4008 14.8064 15.1853 15.5325 15.8426 16.1094 16.3264 16.4864 16.5821 16.6065 9.0131 9.4716 9.9252 10.3729 10.8133 11.2450 11.6661 12.0744 12.4676 12.8426 13.1963 13.5248 13.8237 14.0885 14.3137 14.4939 14.6233 14.6959 14.7062 8.0225 8.4292 8.8311 9.2273 9.6165 9.9973 10.3679 10.7265 11.0707 11.3978 11.7050 11.9889 12.2456 12.4711 12.6610 12.8106 12.9151 12.9699 12.9706 7.1051 7.4640 7.8184 8.1673 8.5096 8.8439 9.1687 9.4821 9.7821 10.0664 10.3322 10.5767 10.7965 10.9882 11.1480 11.2721 11.3566 11.3976 11.3917 6.2609 6.5761 6.8870 7.1928 7.4923 7.7844 8.0676 8.3404 8.6008 8.8467 9.0759 9.2858 9.4734 9.6360 9.7703 9.8731 9.9413 9.9717 9.9617 5.4888 5.7643 6.0357 6.3023 6.5632 6.8172 7.0631 7.2993 7.5243 7.7363 7.9331 8.1126 8.2724 8.4099 8.5225 8.6076 8.6625 8.6848 8.6723 4.7872 5.0267 5.2625 5.4938 5.7199 5.9397 6.1521 6.3559 6.5495 6.7313 6.8997 7.0527 7.1883 7.3042 7.3985 7.4688 7.5130 7.5292 7.5154 4.1537 4.3608 4.5645 4.7643 4.9593 5.1486 5.3312 5.5061 5.6719 5.8273 5.9708 6.1007 6.2153 6.3129 6.3915 6.4495 6.4850 6.4965 6.4825 3.5851 3.7633 3.9385 4.1101 4.2774 4.4396 4.5960 4.7454 4.8868 5.0190 5.1407 5.2506 5.3472 5.4290 5.4945 5.5422 5.5707 5.5786 5.5649 3.0780 3.2306 3.3805 3.5271 3.6700 3.8083 3.9414 4.0685 4.1885 4.3005 4.4034 4.4960 4.5771 4.6454 4.6998 4.7389 4.7617 4.7671 4.7540 2.6287 2.7586 2.8861 3.0108 3.1322 3.2496 3.3624 3.4699 3.5713 3.6657 3.7523 3.8300 3.8978 3.9548 3.9998 4.0318 4.0500 4.0534 4.0413 2.2329 2.3429 2.4509 2.5564 2.6590 2.7581 2.8532 2.9438 3.0291 3.1083 3.1808 3.2458 3.3023 3.3495 3.3866 3.4128 3.4273 3.4293 3.4183 1.8865 1.9792 2.0702 2.1589 2.2452 2.3284 2.4083 2.4842 2.5555 2.6218 2.6822 2.7363 2.7831 2.8222 2.8527 2.8740 2.8855 2.8866 2.8767 1.5852 1.6629 1.7391 1.8134 1.8856 1.9552 2.0218 2.0851 2.1445 2.1996 2.2498 2.2946 2.3333 2.3655 2.3904 2.4077 2.4168 2.4172 2.4085 1.3248 1.3896 1.4531 1.5149 1.5750 1.6328 1.6882 1.7407 1.7900 1.8356 1.8770 1.9140 1.9458 1.9722 1.9926 2.0066 2.0137 2.0137 2.0061 1.1011 1.1548 1.2074 1.2587 1.3084 1.3562 1.4020 1.4454 1.4860 1.5235 1.5576 1.5879 1.6140 1.6355 1.6521 1.6634 1.6690 1.6687 1.6622 0.9101 0.9544 0.9978 1.0400 1.0810 1.1203 1.1580 1.1936 1.2269 1.2577 1.2856 1.3103 1.3316 1.3491 1.3625 1.3716 1.3760 1.3755 1.3699 0.7481 0.7845 0.8200 0.8546 0.8881 0.9204 0.9511 0.9802 1.0074 1.0325 1.0553 1.0754 1.0927 1.1068 1.1176 1.1249 1.1283 1.1277 1.1230 0.6115 0.6412 0.6702 0.6984 0.7257 0.7519 0.7770 0.8006 0.8227 0.8431 0.8615 0.8778 0.8917 0.9031 0.9118 0.9176 0.9202 0.9197 0.9157 0.4971 0.5211 0.5447 0.5675 0.5897 0.6109 0.6312 0.6503 0.6681 0.6846 0.6994 0.7125 0.7237 0.7329 0.7398 0.7444 0.7465 0.7459 0.7426 0.4018 0.4212 0.4402 0.4586 0.4764 0.4936 0.5099 0.5252 0.5396 0.5528 0.5647 0.5752 0.5842 0.5915 0.5970 0.6006 0.6022 0.6017 0.5990 0.3229 0.3385 0.3537 0.3685 0.3828 0.3965 0.4096 0.4219 0.4334 0.4439 0.4534 0.4618 0.4689 0.4747 0.4791 0.4819 0.4831 0.4827 0.4804 0.2581 0.2705 0.2827 0.2945 0.3059 0.3168 0.3272 0.3370 0.3461 0.3545 0.3620 0.3686 0.3743 0.3789 0.3823 0.3845 0.3855 0.3851 0.3833 0.2051 0.2150 0.2246 0.2340 0.2430 0.2516 0.2599 0.2676 0.2748 0.2815 0.2874 0.2927 0.2971 0.3007 0.3034 0.3051 0.3058 0.3055 0.3040 0.1621 0.1699 0.1775 0.1848 0.1919 0.1988 0.2052 0.2113 0.2170 0.2222 0.2269 0.2310 0.2345 0.2373 0.2394 0.2408 0.2413 0.2410 0.2398 0.1273 0.1335 0.1394 0.1452 0.1508 0.1561 0.1612 0.1660 0.1704 0.1745 0.1781 0.1813 0.1841 0.1863 0.1879 0.1889 0.1893 0.1891 0.1882 0.0995 0.1042 0.1089 0.1134 0.1177 0.1219 0.1259 0.1296 0.1330 0.1362 0.1390 0.1415 0.1437 0.1454 0.1466 0.1474 0.1477 0.1475 0.1468 0.0773 0.0810 0.0846 0.0881 0.0914 0.0947 0.0977 0.1006 0.1033 0.1057 0.1079 0.1098 0.1115 0.1128 0.1138 0.1144 0.1146 0.1144 0.1138 0.0597 0.0625 0.0653 0.0680 0.0706 0.0731 0.0754 0.0777 0.0797 0.0816 0.0833 0.0848 0.0860 0.0870 0.0878 0.0882 0.0884 0.0883 0.0878 0.0458 0.0480 0.0501 0.0522 0.0542 0.0561 0.0579 0.0596 0.0612 0.0626 0.0639 0.0650 0.0660 0.0668 0.0673 0.0677 0.0678 0.0677 0.0673 0.0350 0.0366 0.0383 0.0398 0.0414 0.0428 0.0442 0.0455 0.0467 0.0478 0.0488 0.0496 0.0503 0.0509 0.0513 0.0516 0.0517 0.0516 0.0513 0.0265 0.0278 0.0290 0.0302 0.0314 0.0325 0.0335 0.0345 0.0354 0.0362 0.0370 0.0376 0.0382 0.0386 0.0389 0.0391 0.0392 0.0391 0.0389 0.0200 0.0210 0.0219 0.0228 0.0237 0.0245 0.0253 0.0260 0.0267 0.0273 0.0279 0.0284 0.0288 0.0291 0.0294 0.0295 0.0296 0.0295 0.0293 0.0150 0.0157 0.0164 0.0171 0.0178 0.0184 0.0190 0.0195 0.0200 0.0205 0.0209 0.0213 0.0216 0.0218 0.0220 0.0221 0.0222 0.0221 0.0220 0.0112 0.0117 0.0123 0.0128 0.0132 0.0137 0.0141 0.0146 0.0149 0.0153 0.0156 0.0159 0.0161 0.0163 0.0164 0.0165 0.0165 0.0165 0.0164 0.0083 0.0087 0.0091 0.0095 0.0098 0.0102 0.0105 0.0108 0.0111 0.0113 0.0116 0.0118 0.0119 0.0121 0.0122 0.0122 0.0122 0.0122 0.0121 0.0061 0.0064 0.0067 0.0070 0.0072 0.0075 0.0077 0.0080 0.0082 0.0083 0.0085 0.0087 0.0088 0.0089 0.0090 0.0090 0.0090 0.0090 0.0089 0.0045 0.0047 0.0049 0.0051 0.0053 0.0055 0.0057 0.0058 0.0060 0.0061 0.0062 0.0063 0.0064 0.0065 0.0066 0.0066 0.0066 0.0066 0.0066 0.0033 0.0034 0.0036 0.0037 0.0039 0.0040 0.0041 0.0042 0.0044 0.0045 0.0045 0.0046 0.0047 0.0047 0.0048 0.0048 0.0048 0.0048 0.0048 0.0024 0.0025 0.0026 0.0027 0.0028 0.0029 0.0030 0.0031 0.0032 0.0032 0.0033 0.0033 0.0034 0.0034 0.0035 0.0035 0.0035 0.0035 0.0035 0.0017 0.0018 0.0019 0.0019 0.0020 0.0021 0.0021 0.0022 0.0023 0.0023 0.0024 0.0024 0.0024 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0012 0.0013 0.0013 0.0014 0.0014 0.0015 0.0015 0.0016 0.0016 0.0017 0.0017 0.0017 0.0017 0.0018 0.0018 0.0018 0.0018 0.0018 0.0018 0.0009 0.0009 0.0009 0.0010 0.0010 0.0011 0.0011 0.0011 0.0012 0.0012 0.0012 0.0012 0.0012 0.0013 0.0013 0.0013 0.0013 0.0013 0.0013 0.0006 0.0006 0.0007 0.0007 0.0007 0.0007 0.0008 0.0008 0.0008 0.0008 0.0008 0.0009 0.0009 0.0009 0.0009 0.0009 0.0009 0.0009 0.0009 0.0004 0.0004 0.0005 0.0005 0.0005 0.0005 0.0005 0.0006 0.0006 0.0006 0.0006 0.0006 0.0006 0.0006 0.0006 0.0006 0.0006 0.0006 0.0006 0.0003 0.0003 0.0003 0.0003 0.0003 0.0004 0.0004 0.0004 0.0004 0.0004 0.0004 0.0004 0.0004 0.0004 0.0004 0.0004 0.0004 0.0004 0.0004 0.0002 0.0002 0.0002 0.0002 0.0002 0.0002 0.0003 0.0003 0.0003 0.0003 0.0003 0.0003 0.0003 0.0003 0.0003 0.0003 0.0003 0.0003 0.0003 0.0001 0.0001 0.0001 0.0001 0.0002 0.0002 0.0002 0.0002 0.0002 0.0002 0.0002 0.0002 0.0002 0.0002 0.0002 0.0002 0.0002 0.0002 0.0002 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 39 through 57 47.5000 48.7500 50.0000 47.5000 45.0000 42.5000 40.0000 37.5000 35.0000 32.5000 30.0000 27.5000 25.0000 22.5000 20.0000 17.5000 15.0000 12.5000 10.0000 43.2455 43.8481 43.9421 42.6772 40.9037 38.9051 36.7905 34.6085 32.3836 30.1296 27.8551 25.5655 23.2647 20.9553 18.6393 16.3182 13.9931 11.6650 9.3345 39.2289 39.4673 39.2555 38.3751 37.0444 35.4377 33.6596 31.7704 29.8062 27.7893 25.7342 23.6507 21.5457 19.4242 17.2900 15.1459 12.9941 10.8363 8.6740 35.5137 35.5619 35.2620 34.5473 33.4845 32.1645 30.6614 29.0284 27.3016 25.5062 23.6594 21.7738 19.8584 17.9198 15.9632 13.9925 12.0107 10.0203 8.0234 32.0931 32.0413 31.7197 31.1029 30.2163 29.1076 27.8256 26.4109 24.8952 23.3022 21.6498 19.9513 18.2168 16.4541 14.6690 12.8664 11.0500 9.2228 7.3872 28.9434 28.8388 28.5198 27.9747 27.2151 26.2679 25.1645 23.9348 22.6044 21.1941 19.7205 18.1967 16.6329 15.0374 13.4165 11.7755 10.1185 8.4490 6.7698 26.0406 25.9092 25.6034 25.1170 24.4563 23.6373 22.6809 21.6085 20.4403 19.1935 17.8830 16.5207 15.1166 13.6787 12.2135 10.7265 9.2220 7.7037 6.1748 23.3649 23.2216 22.9342 22.4988 21.9193 21.2057 20.3724 19.4349 18.4087 17.3080 16.1454 14.9315 13.6754 12.3850 11.0664 9.7250 8.3653 6.9910 5.6054 20.9002 20.7542 20.4875 20.0977 19.5872 18.9628 18.2345 17.4137 16.5124 15.5420 14.5129 13.4346 12.3152 11.1617 9.9801 8.7755 7.5522 6.3141 5.0643 18.6332 18.4902 18.2452 17.8967 17.4463 16.8988 16.2613 15.5424 14.7513 13.8972 12.9886 12.0337 11.0396 10.0126 8.9582 7.8812 6.7858 5.6755 4.5535 16.5529 16.4163 16.1932 15.8824 15.4851 15.0048 14.4467 13.8174 13.1238 12.3735 11.5734 10.7305 9.8509 8.9402 8.0033 7.0446 6.0681 5.0771 4.0746 14.6493 14.5213 14.3195 14.0433 13.6934 13.2724 12.7842 12.2338 11.6269 10.9693 10.2668 9.5252 8.7497 7.9453 7.1163 6.2668 5.4002 4.5198 3.6284 12.9132 12.7949 12.6138 12.3691 12.0617 11.6933 11.2670 10.7866 10.2567 9.6818 9.0669 8.4167 7.7357 7.0280 6.2977 5.5482 4.7827 4.0042 3.2153 11.3359 11.2279 11.0663 10.8505 10.5811 10.2595 9.8881 9.4699 9.0084 8.5075 7.9710 7.4029 6.8071 6.1872 5.5465 4.8883 4.2153 3.5301 2.8352 9.9088 9.8112 9.6679 9.4784 9.2431 8.9632 8.6405 8.2775 7.8768 7.4417 6.9753 6.4809 5.9618 5.4210 4.8615 4.2859 3.6970 3.0969 2.4878 8.6231 8.5358 8.4094 8.2437 8.0391 7.7963 7.5169 7.2027 6.8561 6.4795 6.0755 5.6470 5.1965 4.7268 4.2403 3.7394 3.2264 2.7033 2.1721 7.4704 7.3928 7.2820 7.1379 6.9606 6.7508 6.5097 6.2388 5.9400 5.6153 5.2668 4.8968 4.5076 4.1014 3.6804 3.2465 2.8018 2.3480 1.8869 6.4417 6.3734 6.2769 6.1520 5.9990 5.8185 5.6113 5.3787 5.1221 4.8432 4.5438 4.2257 3.8909 3.5413 3.1786 2.8045 2.4209 2.0292 1.6310 5.5285 5.4687 5.3851 5.2775 5.1461 4.9913 4.8140 4.6150 4.3956 4.1571 3.9010 3.6288 3.3421 3.0425 2.7315 2.4106 2.0812 1.7448 1.4026 4.7218 4.6699 4.5978 4.5056 4.3933 4.2613 4.1101 3.9406 3.7538 3.5507 3.3326 3.1007 2.8563 2.6008 2.3354 2.0614 1.7801 1.4926 1.2000 4.0131 3.9683 3.9066 3.8279 3.7323 3.6202 3.4920 3.3483 3.1899 3.0178 2.8329 2.6362 2.4289 2.2120 1.9866 1.7539 1.5147 1.2702 1.0213 3.3938 3.3554 3.3028 3.2360 3.1551 3.0603 2.9521 2.8308 2.6972 2.5520 2.3959 2.2299 2.0549 1.8717 1.6813 1.4845 1.2823 1.0754 0.8648 2.8556 2.8229 2.7783 2.7220 2.6538 2.5741 2.4831 2.3812 2.2690 2.1471 2.0160 1.8766 1.7296 1.5756 1.4155 1.2500 1.0798 0.9057 0.7284 2.3905 2.3627 2.3252 2.2779 2.2208 2.1540 2.0779 1.9928 1.8990 1.7971 1.6876 1.5711 1.4482 1.3194 1.1855 1.0470 0.9046 0.7588 0.6103 1.9908 1.9674 1.9360 1.8965 1.8489 1.7933 1.7299 1.6591 1.5812 1.4964 1.4054 1.3085 1.2062 1.0991 0.9877 0.8724 0.7538 0.6324 0.5086 1.6492 1.6297 1.6036 1.5707 1.5312 1.4852 1.4327 1.3741 1.3096 1.2395 1.1642 1.0840 0.9994 0.9107 0.8185 0.7230 0.6248 0.5242 0.4216 1.3591 1.3429 1.3212 1.2941 1.2615 1.2235 1.1803 1.1321 1.0790 1.0213 0.9593 0.8933 0.8236 0.7506 0.6746 0.5960 0.5151 0.4322 0.3477 1.1140 1.1006 1.0828 1.0605 1.0338 1.0026 0.9673 0.9277 0.8842 0.8370 0.7863 0.7322 0.6752 0.6154 0.5531 0.4887 0.4223 0.3544 0.2851 0.9083 0.8973 0.8827 0.8644 0.8426 0.8172 0.7884 0.7562 0.7208 0.6823 0.6410 0.5969 0.5505 0.5017 0.4510 0.3985 0.3444 0.2890 0.2325 0.7365 0.7275 0.7156 0.7008 0.6831 0.6625 0.6391 0.6130 0.5843 0.5532 0.5197 0.4840 0.4464 0.4069 0.3658 0.3232 0.2794 0.2344 0.1886 0.5940 0.5867 0.5771 0.5651 0.5508 0.5342 0.5153 0.4943 0.4712 0.4461 0.4191 0.3903 0.3600 0.3281 0.2950 0.2607 0.2253 0.1891 0.1522 0.4764 0.4705 0.4628 0.4532 0.4417 0.4284 0.4132 0.3964 0.3778 0.3577 0.3361 0.3130 0.2887 0.2632 0.2366 0.2091 0.1808 0.1517 0.1221 0.3800 0.3753 0.3691 0.3614 0.3522 0.3416 0.3296 0.3161 0.3013 0.2853 0.2680 0.2497 0.2303 0.2099 0.1888 0.1668 0.1442 0.1210 0.0974 0.3014 0.2977 0.2928 0.2866 0.2794 0.2709 0.2614 0.2507 0.2390 0.2263 0.2126 0.1980 0.1827 0.1665 0.1497 0.1323 0.1144 0.0960 0.0773 0.2378 0.2348 0.2309 0.2261 0.2203 0.2137 0.2061 0.1977 0.1885 0.1784 0.1677 0.1562 0.1441 0.1314 0.1181 0.1044 0.0902 0.0757 0.0610 0.1865 0.1842 0.1811 0.1773 0.1728 0.1676 0.1617 0.1551 0.1478 0.1400 0.1315 0.1225 0.1130 0.1030 0.0926 0.0819 0.0708 0.0594 0.0478 0.1455 0.1437 0.1413 0.1383 0.1348 0.1307 0.1261 0.1209 0.1153 0.1092 0.1026 0.0955 0.0881 0.0804 0.0723 0.0639 0.0552 0.0464 0.0373 0.1128 0.1114 0.1096 0.1073 0.1045 0.1014 0.0978 0.0938 0.0894 0.0846 0.0795 0.0741 0.0684 0.0623 0.0560 0.0495 0.0428 0.0360 0.0289 0.0870 0.0859 0.0845 0.0827 0.0806 0.0782 0.0754 0.0723 0.0689 0.0653 0.0613 0.0571 0.0527 0.0481 0.0432 0.0382 0.0330 0.0277 0.0223 0.0667 0.0659 0.0648 0.0634 0.0618 0.0599 0.0578 0.0554 0.0529 0.0500 0.0470 0.0438 0.0404 0.0369 0.0331 0.0293 0.0253 0.0213 0.0171 0.0509 0.0502 0.0494 0.0484 0.0471 0.0457 0.0441 0.0423 0.0403 0.0382 0.0359 0.0334 0.0308 0.0281 0.0253 0.0223 0.0193 0.0162 0.0130 0.0386 0.0381 0.0374 0.0367 0.0357 0.0346 0.0334 0.0320 0.0305 0.0289 0.0272 0.0253 0.0234 0.0213 0.0192 0.0169 0.0146 0.0123 0.0099 0.0291 0.0287 0.0282 0.0276 0.0269 0.0261 0.0252 0.0242 0.0230 0.0218 0.0205 0.0191 0.0176 0.0161 0.0144 0.0128 0.0110 0.0093 0.0075 0.0218 0.0215 0.0212 0.0207 0.0202 0.0196 0.0189 0.0181 0.0173 0.0163 0.0154 0.0143 0.0132 0.0120 0.0108 0.0096 0.0083 0.0069 0.0056 0.0162 0.0160 0.0158 0.0154 0.0150 0.0146 0.0141 0.0135 0.0129 0.0122 0.0114 0.0107 0.0098 0.0090 0.0081 0.0071 0.0062 0.0052 0.0042 0.0120 0.0119 0.0117 0.0114 0.0111 0.0108 0.0104 0.0100 0.0095 0.0090 0.0085 0.0079 0.0073 0.0066 0.0060 0.0053 0.0046 0.0038 0.0031 0.0089 0.0087 0.0086 0.0084 0.0082 0.0080 0.0077 0.0074 0.0070 0.0066 0.0062 0.0058 0.0054 0.0049 0.0044 0.0039 0.0034 0.0028 0.0023 0.0065 0.0064 0.0063 0.0062 0.0060 0.0058 0.0056 0.0054 0.0051 0.0049 0.0046 0.0043 0.0039 0.0036 0.0032 0.0028 0.0025 0.0021 0.0017 0.0047 0.0047 0.0046 0.0045 0.0044 0.0042 0.0041 0.0039 0.0037 0.0035 0.0033 0.0031 0.0029 0.0026 0.0023 0.0021 0.0018 0.0015 0.0012 0.0034 0.0034 0.0033 0.0032 0.0032 0.0031 0.0030 0.0028 0.0027 0.0026 0.0024 0.0022 0.0021 0.0019 0.0017 0.0015 0.0013 0.0011 0.0009 0.0025 0.0024 0.0024 0.0023 0.0023 0.0022 0.0021 0.0020 0.0019 0.0018 0.0017 0.0016 0.0015 0.0014 0.0012 0.0011 0.0009 0.0008 0.0006 0.0018 0.0017 0.0017 0.0017 0.0016 0.0016 0.0015 0.0015 0.0014 0.0013 0.0012 0.0012 0.0011 0.0010 0.0009 0.0008 0.0007 0.0006 0.0005 0.0013 0.0012 0.0012 0.0012 0.0012 0.0011 0.0011 0.0010 0.0010 0.0009 0.0009 0.0008 0.0008 0.0007 0.0006 0.0005 0.0005 0.0004 0.0003 0.0009 0.0009 0.0009 0.0008 0.0008 0.0008 0.0008 0.0007 0.0007 0.0007 0.0006 0.0006 0.0005 0.0005 0.0004 0.0004 0.0003 0.0003 0.0002 0.0006 0.0006 0.0006 0.0006 0.0006 0.0006 0.0005 0.0005 0.0005 0.0005 0.0004 0.0004 0.0004 0.0003 0.0003 0.0003 0.0002 0.0002 0.0002 0.0004 0.0004 0.0004 0.0004 0.0004 0.0004 0.0004 0.0004 0.0003 0.0003 0.0003 0.0003 0.0003 0.0002 0.0002 0.0002 0.0002 0.0001 0.0001 0.0003 0.0003 0.0003 0.0003 0.0003 0.0003 0.0003 0.0002 0.0002 0.0002 0.0002 0.0002 0.0002 0.0002 0.0001 0.0001 0.0001 0.0001 0.0001 0.0002 0.0002 0.0002 0.0002 0.0002 0.0002 0.0002 0.0002 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 58 through 61 7.5000 5.0000 2.5000 0 7.0023 4.6688 2.3346 0 6.5083 4.3401 2.1704 0 6.0216 4.0162 2.0087 0 5.5455 3.6994 1.8504 0 5.0833 3.3917 1.6966 0 4.6377 3.0949 1.5484 0 4.2112 2.8108 1.4064 0 3.8056 2.5405 1.2713 0 3.4226 2.2852 1.1436 0 3.0633 2.0456 1.0238 0 2.7284 1.8223 0.9121 0 2.4182 1.6154 0.8086 0 2.1328 1.4249 0.7133 0 1.8718 1.2506 0.6261 0 1.6345 1.0922 0.5469 0 1.4201 0.9490 0.4752 0 1.2276 0.8205 0.4109 0 1.0558 0.7057 0.3534 0 0.9034 0.6039 0.3024 0 0.7690 0.5141 0.2575 0 0.6512 0.4353 0.2180 0 0.5485 0.3667 0.1837 0 0.4596 0.3073 0.1539 0 0.3831 0.2561 0.1283 0 0.3176 0.2124 0.1064 0 0.2619 0.1751 0.0877 0 0.2147 0.1436 0.0719 0 0.1752 0.1171 0.0587 0 0.1421 0.0950 0.0476 0 0.1146 0.0767 0.0384 0 0.0920 0.0615 0.0308 0 0.0734 0.0491 0.0246 0 0.0582 0.0389 0.0195 0 0.0459 0.0307 0.0154 0 0.0360 0.0241 0.0121 0 0.0281 0.0188 0.0094 0 0.0218 0.0146 0.0073 0 0.0168 0.0112 0.0056 0 0.0129 0.0086 0.0043 0 0.0098 0.0066 0.0033 0 0.0075 0.0050 0.0025 0 0.0056 0.0038 0.0019 0 0.0042 0.0028 0.0014 0 0.0031 0.0021 0.0011 0 0.0023 0.0016 0.0008 0 0.0017 0.0011 0.0006 0 0.0013 0.0008 0.0004 0 0.0009 0.0006 0.0003 0 0.0007 0.0004 0.0002 0 0.0005 0.0003 0.0002 0 0.0003 0.0002 0.0001 0 0.0002 0.0002 0.0001 0 0.0002 0.0001 0.0001 0 0.0001 0.0001 0.0000 0 0.0001 0.0001 0.0000 0 0.0001 0.0000 0.0000 0 0.0000 0.0000 0.0000 0 0.0000 0.0000 0.0000 0 0.0000 0.0000 0.0000 0 0 0 0 0
ans = 48.7500
contourf(0:h:x,0:h:y,T.')
colorbar
%--------------------------------------------------------------------------------------------------------------------------%
% Analytical Solution
AT=zeros(rows,columns); %% AT is Matrix, filled with zeros until conditions are determined
%--------------------------------------------------------------------------------------------------------------------------%
%% Ammend Matrix with boundary conditions
for c=1:columns
d=(c-1)*h; %% Variable 'd' is equal to c-1*user grid spacing
if d<=2/3*x %% If variable 'd' is less than or equal to 2/3 of x complete following formula
AT(1,c)=12.5*d;
else %% If variable 'd' is greater than or equal to 2/3 of x complete following formula
AT(1,c)= -25*d+150;
end
end
while true %% Iterate until thermal equilibrium is reached
AT_new = AT;
for i = 2:(rows-1) %% Calculate new temperatures for interior points
for j = 2:(columns-1)
for n = 1:200
AT_new(i,j) = AT_new+(sin(2 * n * pi / 3) / (n^2 * sinh(n * pi))) * sin(n * pi * x / 6) * sin(n * pi * y / 6);
end
end
end
end
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 61-by-61.
fprintf('Temperature from Analytical Solution = \n%AT')
disp(AT)
%--------------------------------------------------------------------------------------------------------------------------%
% Plot the final temperature distribution
figure(1);
contourf(flip(T));
colormap("jet");
colorbar;
title('Temperature Distribution');
xlabel('X Axis');
ylabel('Y Axis');
axis equal tight
  5 Comments
Torsten
Torsten on 16 Feb 2024
Edited: Torsten on 16 Feb 2024
X = 0:0.1:6;
nx = numel(X);
Y = 0:0.1:6;
ny = numel(Y);
mmax = 100;
tol = 1e-6;
T = zeros(nx,ny);
for ix = 1:nx
x = X(ix);
for iy = 1:ny
y = Y(iy);
error = Inf;
im = 1;
while error > tol && im <= mmax
summand = sin(2*pi*im/3)/(im^2*sinh(im*pi))*sin(im*pi*x/6)*sinh(im*pi*y/6);
error = abs(summand);
T(ix,iy) = T(ix,iy) + summand;
im = im+1;
end
T(ix,iy) = 450/pi^2*T(ix,iy);
end
end
contourf(X,Y,T.')
colorbar

Sign in to comment.

Answers (1)

William Rose
William Rose on 16 Feb 2024
Edited: William Rose on 16 Feb 2024
[Edit: add a line of code to display the maximum temperature for each value of N.]
Another excellent answer from @Torsten!
The boundary conditions are T=0 on three sides (x=0, x=6, y=6). On the y=0 edge, T=0 to 50 deg (linear ramp) from x=0 to x=4, then T ramps down from 50 to 0 deg, from x=4 to x=6. Therefore we expect to see T=0 along 3 edges, and at all four corners. We expect to see t=50 at (x,y)=(4,0).
Your plot has "x" running vertically, which is fine of course - just so you know.
Analytical:
The script below computes and plots the analytical temperature distribution using summations of N=5, 10, and 200 terms. You can see small differences between the plots, near the hottest point.
x=0:.06:6; y=0:.08:6;
% I like having different number of elements along x and y for grids,
% to protect against transposing without realizing.
N=[5,10,200]; % elements in summation
T=zeros(length(y),length(x),length(N));
for i=1:length(N)
T(:,:,i)=temp(N(i),x,y); % analytical solution for temperature
figure; contourf(x,y,T(:,:,i)) % plot temperature
axis equal; xlabel('X'); ylabel('Y')
title(['Analytical Temperature Solution, N=',num2str(N(i))])
clim([0,50]); colorbar % use same color range for all plots
end
fprintf('Maximum temperature for N=%d,%d,%d: %.1f,%.1f,%.1f.\n',...
N,max(T,[],[1 2]))
Maximum temperature for N=5,10,200: 46.7,48.2,49.5.
function T=temp(N,x,y)
T=zeros(length(y),length(x));
for n=1:N
T=T+(sin(2*pi*n/3)*sinh(n*pi*y'/6)*sin(n*pi*x/6))/(n^2*sinh(pi*n));
end
T=450*T/pi^2;
end
@Torsten's contour plot shows the non-zero temperature boundary along the edge y=6, which disagrees with the boundary conditions in the document you posted. I get the same result as Torsten. Therefore I think the analytical solution has an error.
Good luck.
  6 Comments
Christopher
Christopher on 25 Feb 2024
for my numerical solution, the matrix size is determined by the user input for h, which is then checked it is divisibe by 6, if so the matrix is that size.
when I enter that code I do not get a matrix the same size as the numerical solution?
I have the following code now which provides me with the same matrix sizes but the values for the analytical matrix are 'inf', which im assuming is infinity, but I do not know where I am going wrong to get that value instead of values that are close to the numerical matrix
any help would be much appreciated
clc %% CLear Command Window
clear %% Clear Variables from code
close all %% Close all figure windows
%--------------------------------------------------------------------------------------------------------------------------%
% Define values for code
x=6; %% X Variable equal to
y=6; %% Y Variable equal to
k= 143; %% Conductivity of Aluminium
p= 2.8*10^3; %% Density value
c= 795; %% Specific heat value
alpha= k/(p*c); %% Calculate Alpha using above values
%--------------------------------------------------------------------------------------------------------------------------%
% User enters their grid spacing
h=input('Enter your material grid spaceing here - '); %% User enters their grid spaceing
while mod(6, h) ~= 0 || h<0 || h>=6 %% Check is users grid spacing is valid by checking divisible into 6
fprintf('Your grid spacing is not valid \n'); %% If grid spaceing entered is not valid tell user
h=input('Enter your material grid spaceing here - ');
end
%--------------------------------------------------------------------------------------------------------------------------%
% Calculate Matrix dimensions
rows= (y/h)+1; %% Matrix rows is x(sheet width) / user input for h
columns= (x/h)+1; %% Matrix columns is y(Sheet Length) / user input h
%--------------------------------------------------------------------------------------------------------------------------%
%% Initialise Matrix
T=zeros(rows,columns); %% T is Matrix, filled with zeros until conditions are determined
%--------------------------------------------------------------------------------------------------------------------------%
%% Ammend Matrix with boundary conditions
for c=1:columns
d=(c-1)*h; %% Variable 'd' is equal to c-1*user grid spacing
if d<=2/3*x %% If variable 'd' is less than or equal to 2/3 of x complete following formula
T(1,c)=12.5*d;
else %% If variable 'd' is greater than or equal to 2/3 of x complete following formula
T(1,c)= -25*d+150;
end
end
%--------------------------------------------------------------------------------------------------------------------------%
% User enters their time step value, this gets checked to ensure its valid
dt=input('Enter your time step here - '); %% User enters their time step here
Fo= (alpha*dt)/(h^2); %% Calculation for Fouriers Number
while Fo<0 || Fo>0.25
fprintf('Your time step is not valid \n'); %% If time step entered is not valid tell user
dt=input('Enter your time step here - ');
end
%--------------------------------------------------------------------------------------------------------------------------%
% Creating Further Matrices
max_change_threshold = 0.01; %% Maximum change allowed for equilibrium, Change this value as needed
time = 0; %% Initialize time
while true %% Iterate until thermal equilibrium is reached
T_new = T;
for i = 2:(rows-1) %% Calculate new temperatures for interior points
for j = 2:(columns-1)
T_new(i,j) = T(i,j) + Fo*(T(i+1,j) + T(i-1,j) + T(i,j+1) + T(i,j-1) - 4*T(i,j));
end
end
%--------------------------------------------------------------------------------------------------------------------------%
% Check for thermal equilibrium
max_change = max(abs(T_new - T),[],"all");
if max_change < max_change_threshold
% Exit loop if thermal equilibrium is reached
break;
end
% Update the temperature matrix and time for the next iteration
T = T_new;
time = time + dt;
end
fprintf('Thermal equilibrium reached at time = %f seconds\n', time); % Display Thermal equilibrium message has been reached to user
fprintf('Temperature from Numerical Solution = \n%T')
disp(T)
%--------------------------------------------------------------------------------------------------------------------------%
% Analytical Solution
AT=zeros(rows,columns); %% AT is Matrix, filled with zeros until conditions are determined
%--------------------------------------------------------------------------------------------------------------------------%
%% Ammend Matrix with boundary conditions
for c=1:columns
d=(c-1)*h; %% Variable 'd' is equal to c-1*user grid spacing
if d<=2/3*x %% If variable 'd' is less than or equal to 2/3 of x complete following formula
AT(1,c)=12.5*d;
else %% If variable 'd' is greater than or equal to 2/3 of x complete following formula
AT(1,c)= -25*d+150;
end
end
%--------------------------------------------------------------------------------------------------------------------------%
% Creating Further Matrices
max_change_threshold = 0.01; %% Maximum change allowed for equilibrium, Change this value as needed
time = 0; %% Initialize time
while true %% Iterate until thermal equilibrium is reached
AT_new = AT;
for i = 2:(rows-1) %% Calculate new temperatures for interior points
for j = 2:(columns-1)
for n=1:100
AT_new(i,j) = AT(i,j) + (sin(2*pi*n/3)/(n^2*sinh(n*pi))*sin(n*pi*x/6)*sinh(n*pi*y/6));
end
AT_new=450*AT_new/pi^2;
end
end
max_change = max(abs(AT_new - AT),[],"all");
if max_change < max_change_threshold
% Exit loop if thermal equilibrium is reached
break;
end
% Update the temperature matrix and time for the next iteration
AT = AT_new;
time = time + dt;
end
fprintf('Temperature from Analytical Solution = \n%AT')
disp(AT)
%--------------------------------------------------------------------------------------------------------------------------%
% Plot the final temperature distribution
figure(1);
contourf(flip(T));
colormap("jet");
colorbar;
title('Temperature Distribution');
xlabel('X Axis');
ylabel('Y Axis');
axis equal tight
Torsten
Torsten on 25 Feb 2024
Why do you use this while loop to compute AT ? Your analytical solution does not depend on t.
And what are x and y in the expression
AT_new(i,j) = AT(i,j) + (sin(2*pi*n/3)/(n^2*sinh(n*pi))*sin(n*pi*x/6)*sinh(n*pi*y/6));
They are both set to 6 and don't change in the for-loops although they had to.

Sign in to comment.

Categories

Find more on MATLAB Mobile Fundamentals in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!