Index exceeds matrix dimensions (Thermal 1d model)

조회 수: 1 (최근 30일)
Aditya Khuller
Aditya Khuller 2017년 6월 28일
댓글: Aditya Khuller 2017년 7월 5일
I'm trying to write a 1D thermal model using a finite difference scheme. I'm still an amateur programmer so I apologize for my ignorance. I keep getting this error: Index exceeds matrix dimensions. I know this means that I'm trying to access an element in an array using an index that exceeds the dimension of the array but I don't know what to do with that information.
N = 15;
% Geometrically increasing grid spacing
z = 0;
zs = [kappa*P/pi]^(1/2);
deltaz = zs/10;
for i = 1:N
deltaz(i+1) = deltaz(i)*(1+1/5);
z(i+1) = z(i)+deltaz(i);
T0 = [[(S0/R^2).*(1-A)]/(e*(5.67*10^-8))]^(1/4);
TN = T0/((2)^(1/2));
T(i+1) = TN - (TN-T0)*exp(-z(i+1)/0.06);
zor(i+1) = deltaz(i+1)*deltaz(i)*(deltaz(i+1)+deltaz(i));
alpha_model(i+1) = 2*K*deltaz(i+1)/zor(i+1);
beta_model(i+1) = 2*K*deltaz(i)/(zor(i+1));
for n= 1:N
T(i+1,n+2) = T(i+1,n+1) + [dt/(rho*cp)].*[alpha_model(i+1).*T(i,n+1)-(alpha_model(i+1) + beta_model(i+1)).*T(i+1,n+1) + beta_model(i+1).*T(i+2,n+1)];
end
end
  댓글 수: 1
Jan
Jan 2017년 6월 28일
편집: Jan 2017년 6월 28일
Start with posting the complete message. Then the readers do not have to guess, which line is failing.
We cannot run your code, because
zs = [kappa*P/pi]^(1/2);
is failing due to unknown kappa. By the way:
zs = sqrt(kappa * P / pi);
is nicer and faster. Do not use square brackets without any reasons. See https://www.mathworks.com/matlabcentral/answers/35676-why-not-use-square-brackets . [] is the concatenation operator.

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

채택된 답변

Jan
Jan 2017년 6월 28일
You define
T(i+1) = TN - (TN-T0)*exp(-z(i+1)/0.06);
but access
T(i+1, n+1)

추가 답변 (0개)

카테고리

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