Index exceeds matrix dimensions (Thermal 1d model)
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Aditya Khuller
am 28 Jun. 2017
Kommentiert: Aditya Khuller
am 5 Jul. 2017
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 Kommentar
Jan
am 28 Jun. 2017
Bearbeitet: Jan
am 28 Jun. 2017
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.
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
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!