MATLAB: Attempted to access t(1,4); index out of bounds because size(t)=[10,3] , how to solve this problem

heat transfer

clc , clear ;
m=2 ; k=28 ;
tinf1=20 ; h1=500 ;
tinf2=30 ; h2=15; l=pi ;
alpha=4*10^-4 ;
dx=1/m ;
dt=200 ;
taw=(dt*alpha)/(dt)^2 ;
treq=1800 ;
imax=( treq /dt)+1;
t1=700-50*sin(dx);
t=zeros(imax,m+1);
t(1,:)=zeros(1,m+1)+t1 ;
for i=1: imax-1 ;
for m=1:m+1 ;
if m==1
t(i+1,m)=taw*t(i,m+1)-(t(i,m)*(taw+h1*dx));
else if m==m
t(i+1,m)=taw*t(i,m+2)-(t(i,m+1)*(taw+h2*dx));
else
t(i+1,m)=taw*(t(i,m-1)-2*t(i,m+1)+t(i,m));
end
end
end
end
ts=t(:,m+1) ;
time=linspace(0,treq , length(ts))

Best Answer

Since you have
size(t)=[10,3]
Then check why you are writing t(1,4)
There is another problem with your for loop
for m=1:m+1
You erasing the value of m