Index exceeds matrix dimensions (Thermal 1d model)
1 view (last 30 days)
Show older comments
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 Comment
Jan
on 28 Jun 2017
Edited: Jan
on 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.
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!