Can someone help me write a matlab program for this? It needs to solve a 20x20 t
ID: 3694393 • Letter: C
Question
Can someone help me write a matlab program for this? It needs to solve a 20x20 temperature grid matrix using two exterior points and two interior points that are inputed by the user. It solves the matrix using equations like the ones below.
Objective Use systems of simultaneous equations to solve a temperature distri- bution problem Introduction A common method for calculating the temperature distribution in a plate is through the use of averaging and simultaneous equations. The assumption is that a plate can be segmented into an nzm grid where the temperature for a particular point is the average of the four points surround ing it. If the point is along an edge then the temperature is the average of the three points surrounding it along with the outside temperature at that point. And if the point is a corner then its temperature is the average of the two points adjacent to it plus the two outside temperatures. 83Explanation / Answer
>> M = [ 1/3 0 0 1/3 1/3 0;
0 0 1/2 0 0 1/2;
0 0 1/2 0 0 1/2;
0 1/3 0 1/3 1/3 0 ]
>> R = rref(M) % T1=0,T2=0,T3=1,T4=0,Ta=0,Tb=0 at equilibrium.
function T = tempgrid(n,top,bottom,left,right)
T = zeros(n);
for i = 1:n
T(1,i) = top(i);
T(n,i) = bottom(i);
T(i,1) = left(i);
T(i,n) = right(i);
end;
variables = (n-2)^2;
M = zeros(variables,variables + 1);
k = 0;
for row = 2:n-1
for col = 2:n-1
k = k + 1;
M(k,k) = 1;
if row == 2
M(k,variables + 1) = M(k,variables + 1) + T(row - 1,col)/4;
else
M(k,k-n+2) = -1/4;
end;
if row == n-1
M(k,variables + 1) = M(k,variables + 1) + T(row +1,col)/4;
else
M(k,k+n-2) = -1/4;
end;
if col == 2
M(k,variables + 1) = M(k,variables + 1) + T(row,col-1)/4;
else
M(k,k-1) = -1/4;
end;
if col == n-1
M(k,variables + 1) = M(k,variables + 1) + T(row,col+1)/4;
else
M(k,k+1) = -1/4;
end;
end;
end;
R = rref(M);
T(2:n-1,2:n-1) = reshape(R(:,variables+1),n-2,n-2)';
>> n = 20;
>> top = ones(1,n); bottom = zeros(1,n);
>> left = ones(1,n); right = zeros(1,n);
>> tempgrid(n,top,bottom,left,right)
>> contourf(M,10) % Create a filled contour plot of M with 10 contour lines.
% Error found at fifth position.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.