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

2 Ansichten (letzte 30 Tage)
Aman Murkar
Aman Murkar am 3 Okt. 2021
Kommentiert: Aman Murkar am 3 Okt. 2021
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);

Antworten (1)

Walter Roberson
Walter Roberson am 3 Okt. 2021
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 Kommentar
Aman Murkar
Aman Murkar am 3 Okt. 2021
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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by