MATLAB Answers

Index in position 2 exceeds array bounds (must not exceed 6). heat transfer PDE finite difference

1 view (last 30 days)
Abdelrahman Eldaly
Abdelrahman Eldaly on 16 Dec 2019
Answered: per isakson on 16 Dec 2019
I am trying to solve this PDE with finite difference with boundry conditions x=1,T=0 ' x=0,dT/dx=0 ' y=0,dT/dy=0 ' y=1, dT/dy=-T
T_old=ones(7,6);
T_old(:,6)=0;
T_old(1,:)=-T_old(2,:)/2+T_old(3,:);
T_new=zeros(5);
i=1;
if i<5
for j=1:5
T_new(i,j)=9/64+1/8*(T_old(i+1,j)+T_old(i+1,j+2))+3/8*(T_old(i,j+1)+T_old(i+2,j+2));
end
i=i+1;
end
my code gives me this error ''index in position 2 exceeds array bounds (must not exceed 6).''

  0 Comments

Sign in to comment.

Answers (1)

per isakson
per isakson on 16 Dec 2019
The term
T_old(i+1,j+2)
causes the error when j==5, because T_old(2,7) doesn't exist. T_old has only 6 columns.

  0 Comments

Sign in to comment.

Sign in to answer this question.