Double-Checked Sizes but Still Get 'Index Exceeds Matrix Dimensions' Error
Show older comments
Hello,
I had a post yesterday talking about the error I keep getting, and thought I understood the issue enough to fix it.
However, I keep getting the same error, mainly in line 71 (denoted below).
A, B, and C are all the same size (1x4). I know BB is larger, but that is my text issue to tackle.
For now, I'm struggling to figure this one out. I attached my code below:
%Given Parameters
a = 10;
b = 1E-4;
d = 400000;
e = 2E-3;
TH = 2000;
TC = 400;
hH = 900;
hL = 1100;
L = .10;
IL = 5;
DX = L/(IL-1);
T(1)=200;
T(2) = (b*T(1)^2+(hH*DX+a)*T(1)-hH*DX*TH)/(a+b*T(1));
T(IL)=50;
T(IL-1)=(b*T(IL)^2+(hL*DX+a)*T(IL)-hL*DX*TC)/(a+b*T(IL));
%Define For-Loop to determine all temperatures based off of initial guesses
for i=3:(IL-2)
T(i)= ((e-(2*a)/(DX^2))*T(i-1)-((2*b)/(DX^2))*T(i-1)^2+...
(1/DX^2-b/(2*DX))*T(i-2)+(b/DX^2)*T(i-1)*T(i-1)+d)/...
(1/DX^2+b/(2*DX)+(b/DX^2)*T(i-1));
end
%Define First and Last Row of Matrix for the BC
% at i=1:
dFi_dTi(1) = (-2*b*T(1))/(DX)-a/DX-hH+(b*T(2))/DX;
dFi_dTip1(1) = (b*T(1))/(DX)+a/DX;
% at i = IL
dFi_dTim1(IL) = (-b*T(IL))/(DX)-a/DX;
dFi_dTi(IL) = (2*b*T(IL))/(DX)+a/DX+hL+(b*T(IL-1))/DX;
for i=2:(IL-1)
dFi_dTim1(i) = a/DX^2-b/(2*DX)+(b*T(i))/(DX^2);
dFi_dTi(i) = e-(2*a)/(DX^2)+(b*T(i+1))/...
(DX^2)+(b*T(i-1))/(DX^2)-(4*b*T(i))/(DX^2);
dFi_dTip1(i) = a/DX^2+b/(2*DX)+(b*T(i))/(DX^2);
end
%Matrix Stuff for Thomas Algorithm
%Matrix Parameters
A(i) = dFi_dTi(i);
B(i) = dFi_dTip1(i);
C(i) = dFi_dTim1(i);
BB = 1:DX:IL;
B(1)=B(1)/A(1);
for i=2:IL
A(i)=A(i)-C(i)*B(i-1); %***LINE 71****
B(i)=B(i)/A(i);
end
BB(1)=BB(1)/A(1);
for i=2:IL
BB(i)=(BB(i)-C(i)*BB(i-1))/A(i);
end
NMI=IL-1;
for i=1:NMI
ii=IL-1;
BB(ii)=BB(ii)-B(ii)*BB(ii+1);
end
I believe all function/variables that rely on i all run from 1 to IL, so I'm not sure how the sizes are mismatched, specifically in line 71, where I keep getting the error.
Any help is appreciated, thank you. If there's more detail or information I can give please ask.
Accepted Answer
More Answers (0)
Categories
Find more on Startup and Shutdown 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!