help-octave
[Top][All Lists]

## Re: Octave Error with Bounds

 From: darkstyle86 Subject: Re: Octave Error with Bounds Date: Sun, 11 Dec 2016 22:52:22 -0800 (PST)

```Good! When I add c(N)=0 to the code, the code progresses but the error changes
to:

error: Project_solver_w_areas: A(I,J): row index out of bounds; value 41 out of
bound 40
error: called from
Project_solver_w_areas at line 71 column 13

I think it has to do with how I'm initializing the temperatures values in
T(i,j) under "Initialization of temperatures using 1-D analytical solution".
But it's a similar problem with bounds.  Any ideas here?  I tried adding a(1)=0
to the code and that didn't help.  Thank you.

________________________________
From: Doug Stewart-4 [via Octave] <address@hidden>
Sent: Friday, December 9, 2016 10:26 PM
To: darkstyle86
Subject: Re: Octave Error with Bounds

On Fri, Dec 9, 2016 at 8:24 PM, darkstyle86 <[hidden
email]</user/SendEmail.jtp?type=node&node=4680990&i=0>> wrote:
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;

you should have a c(N)= something here.

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.

_______________________________________________
Help-octave mailing list
[hidden email]</user/SendEmail.jtp?type=node&node=4680990&i=1>
https://lists.gnu.org/mailman/listinfo/help-octave

--
DAS[Certificate for 206392]

<https://linuxcounter.net/user/206392.html>

_______________________________________________
Help-octave mailing list
[hidden email]</user/SendEmail.jtp?type=node&node=4680990&i=2>
https://lists.gnu.org/mailman/listinfo/help-octave

________________________________
http://octave.1599824.n4.nabble.com/Octave-Error-with-Bounds-tp4680987p4680990.html
To unsubscribe from Octave Error with Bounds, click
here<http://octave.1599824.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4680987&code=cm9ja3N0YXI2ODAxNEBtc24uY29tfDQ2ODA5ODd8LTY5MzAxMDQyNQ==>.

--
View this message in context:
http://octave.1599824.n4.nabble.com/Octave-Error-with-Bounds-tp4680987p4681003.html
Sent from the Octave - General mailing list archive at Nabble.com.

```