[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Octave Error with Bounds
From: |
darkstyle86 |
Subject: |
Octave Error with Bounds |
Date: |
Fri, 9 Dec 2016 17:24:10 -0800 (PST) |
Hello, there may be a post that helps me with my exact problem but I haven't
found it yet, so please direct me to that post if you know of it. Thank
you. I'm putting a code together to determine the 2-D temperature
distribution in a triangular fin.
My base code is as follows:
M=41; % number of grid points in x-direction
N=31; % number of grid points in y-direction
dx=w/(M-1); % delta x
dy=L/(N-1); % delta y
for i=1:M x(i)=dx*i; end
for j=1:N y(i)=dy*j; end
h=2*C*w^-0.5;
% Initialization of temperatures using 1-D analytical solution
for j=1:N
for i=2:(M-1) T(i,j)=Tinf; end
end
%
for iter=1:10
% forward sweep
for i=2:(M-1)
b(1)=-(k*dx*t/L*dy/2*dx+2*k*dy*1/8*t/L*dy^2+h*dx*dy*dx*hyp/L*dy);
c(1)=k*dx*t/L*dy/2*dx;
d(1)=-k*dy*1/8*t/L*dy^2*T(i+1,j)-k*dy*1/8*t/L*dy^2*T(i-1,j)-h*dx*dy*dx*hyp/L*dy*Tinf;
for j=2:(N-1)
a(j)=k*dx*t/L*dy*(j-1.5)*dx;
b(j)=-(k*dx*t/L*dy*(j-0.5)*dx+k*dx*t/L*dy*(j-1.5)*dx+2*k*dy*t/L*(j-1)*(dy^2)+h*dx*dy*2*dx*hyp/L*dy);
c(j)=k*dx*t/L*dy*(j-0.5)*dx;
d(j)=-k*dy*t/L*(j-1)*(dy^2)*T(i+1,j)-k*dy*t/L*(j-1)*(dy^2)*T(i-1,j)-h*dx*dy*2*dx*hyp/L*dy*Tinf;
end
a(N)=k*dx*t/L*dy*(j-1.5)*dx;
b(N)=-(k*dx*t/L*dy*(N-1.5)*dx+2*k*dy*1/2*(t+(t/L)*(L-(dy/2)))*dy/2+h*dx*dy*dx*hyp/L*dy);
d(N)=-k*dy*1/2*(t+(t/L)*(L-(dy/2)))*dy/2*T(i-1,j)-k*dy*1/2*(t+(t/L)*(L-(dy/2)))*dy/2*T(i+1,j)-Q*dx*dy*t/L*(N-1)*dy*dx-h*dx*dy*dx*hyp/L*dy*Tinf;
Ttemp=TDMAsolver(a,b,c,d);
for j=1:N T(i,j)=Ttemp(j); end
end
end
The function TDMAsolver I am using is the following code:
function x = TDMAsolver(a,b,c,d)
%a, b, c are the column vectors for the compressed tridiagonal matrix, d is
the right vector
n = length(b); % n is the number of rows. The first row is i=1.
% Modify the first-row coefficients
c(1) = c(1) / b(1); % Division by zero risk.
d(1) = d(1) / b(1); % Division by zero would imply a singular matrix.
for i = 2:n
id = 1 / (b(i) - c(i-1) * a(i)); % Division by zero risk.
c(i) = c(i)* id; % Last value calculated is redundant.
d(i) = (d(i) - d(i-1) * a(i)) * id;
end
% Now back substitute.
x(n) = d(n);
for i = n-1:-1:1
x(i) = d(i) - c(i) * x(i + 1);
end
The error I'm getting when I run my base code is:
"error: TDMAsolver: A(I): index out of bounds; value 31 out of bound 30
error: called from
TDMAsolver at line 11 column 10
Project_solver_w_areas at line 80 column 14"
I can't figure out what the problem is. Does anyone have any ideas? Thank
you.
--
View this message in context:
http://octave.1599824.n4.nabble.com/Octave-Error-with-Bounds-tp4680987.html
Sent from the Octave - General mailing list archive at Nabble.com.
- Octave Error with Bounds,
darkstyle86 <=
- Re: Octave Error with Bounds, Doug Stewart, 2016/12/09
- Re: Octave Error with Bounds, darkstyle86, 2016/12/12
- Re: Octave Error with Bounds, Doug Stewart, 2016/12/12
- Re: Octave Error with Bounds, darkstyle86, 2016/12/12
- Re: Octave Error with Bounds, Doug Stewart, 2016/12/12
- Re: Octave Error with Bounds, darkstyle86, 2016/12/12
- Re: Octave Error with Bounds, Doug Stewart, 2016/12/12