Index in position 2 exceeds array bounds (must not exceed 50).

조회 수: 2 (최근 30일)
Aman Murkar
Aman Murkar 2021년 10월 3일
댓글: Aman Murkar 2021년 10월 3일
code:
function main
% solution of 2D elliptical solution
% using Line Over Relaxation Method(LSOR)
% ep is accepted error
%Tridiag: Tridiagonal equation solver banded system
%stream function solver for inlet aswell as for outlet with Dirichlet
%conditions
clc;
clear all;
eps = 0.001;
omega = input(' enter the omega value: ');
beta = input (' enter the beta value: ');
n= 100000;
nx = 51;
ny = 51;
T(1:nx, 1:ny-1) = 0;
TN(1:nx, 1:ny-1) = 0;
T(13:nx, 1)= 100;
T(nx, 1:31) = 100;
TN(13:nx, 1)= 100;
TN(nx, 1:31) = 100;
% its number of iteration
coeff = ( 2*(1+beta^2));
for iterations = 1:n
for j = 2:ny-1
a(1:nx-2) = -coeff;
b(1:nx-2)= omega;
c(1:nx-2)= omega;
for i = 2:nx-1
r(i-1) = - coeff*(1-omega)*T(i,j)-omega*beta^2*T(i,j+1)-omega*beta^2*TN(i,j-1);
end
r(1)= r(1)-omega*TN(1,j);
r(nx-2)= r(nx-2)-omega*TN(nx,j);
y = Tridiagonal(c,a,b,r);
for k = 1:nx-2
TN(k+1,j)= y(k);
end
end
error = abs(TN-T);
totalerror = sum(error,'all');
if totalerror <= eps
break
end
T=TN;
end
iterations
contour(TN');
end
result:
enter the omega value: 1.2
enter the beta value: 1
Index in position 2 exceeds array bounds (must not exceed 50).
Error in sf1 (line 30)
r(i-1) = - coeff*(1-omega)*T(i,j)-omega*beta^2*T(i,j+1)-omega*beta^2*TN(i,j-1);

답변 (1개)

Walter Roberson
Walter Roberson 2021년 10월 3일
ny = 51;
T(1:nx, 1:ny-1) = 0;
You initialize 51-1 = 50 columns in T
for j = 2:ny-1
j will be as much as 51-1 = 50
r(i-1) = - coeff*(1-omega)*T(i,j)-omega*beta^2*T(i,j+1)-omega*beta^2*TN(i,j-1);
When j becomes 50, then j+1 becomes 51, and T(2,51) would be asked for, but column 51 of T has not been initialized
  댓글 수: 1
Aman Murkar
Aman Murkar 2021년 10월 3일
thanks I got it . Its my mistake there should be T(1:nx, 1;ny) by mistake i wrote 1:ny-1.
Thanks for response

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by