Matlab help
Ok so for my applied math class, we are writing a matlab script to preform finite differencing on a rectangular heat fin to determine the temperature profile of the heat with with distance. Now before anyone says it I know this is much more easily done in solid works but that apparently not the point according to my prof. The heat fin in question can experience 3 boundry conditions on the outside edge of the fin, one its insulated, 2 its at ambient temperature, 3 convection occurs. The below is what I have so far but the values for y and t are a little funky. Any help and explanations would be greatly appreciated.
n=input('type number of intervals: ');
bc=input('Boundary conditions: for an insulated system, type 1. if outer edge is at ambient temperature, type 2. if convection occurs at the outer edge, type 3: ');
tb=298; %temp of base of fin
tsurr=273; %temp of surroundings
k=1; %thermal condctivity
h=1; %heat transfer
thck=1; %thickness of fin
l=1; %length of fin
w=1; %width of fin
m=1;
%values derived from above
a=w*thck; %crosssectional area of fin
dz=l/n; %interval size
p=2*w+2*thck; %perimeter of fin
% initial equation is T''2hP/ka(TTa)=0
% after transform equation becomes y''(2hpl^2/Ka)y=0
% y = TTsurr/TbTsurr, derivatives of y are with respect to z (z=x/l)
alpha=(2*h*p*l*l)/(k*a);
% set y and solution vector sizes. set x matrix size
z=zeros(n);
y=zeros(n,m);
g=zeros(n,m);
x=zeros(n,m);
t=zeros(n,m);
z(1,1)=1;
g(1)=1;
% build matrix between boundaries
for i=2:1:n1
z(i,i1)=l/dz^2;
z(i,i)=alpha+2/dz^2;
z(i,i+1)=l/dz^2;
g(i)=0;
end
% establish boundary conditions
for i=n
if bc==1
z(i,i1)=2/dz^2;
z(i,i)=alpha(2/dz^2);
end
if bc==2
z(i,i1)=0;
z(i,i)=1;
end
if bc==3
z(i,i1)=2/dz^2;
z(i,i)=alpha(2/dz^2)(2*h*l)/(k*dz);
end
end
% Implement Thomas's Algorithm to solve
for i=2:1:n
z(i,i)= z(i,i)(z(i,i1)/z(i1,i1))*z(i1,i);
g(i)=g(i)(z(i,i1)/z(i1,i1))*g(i1);
z(i,i1)=0;
end
y(n)=g(n)/z(n,n);
for i=n1:1:1
y(i)=(g(i)z(i,i+1)*y(i+1))/z(i,i);
end
x(1)=0;
for i=2:1:n+1
x(i)=x(i1)+dz;
end
