[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Octave Error with Bounds
From: |
darkstyle86 |
Subject: |
Re: Octave Error with Bounds |
Date: |
Mon, 12 Dec 2016 16:12:56 -0800 (PST) |
Yes, it worked! Obviously, I need more Octave training. Now for my second
question about obtaining a curve for a single I value from my 2-D solution. I
tried "T1=T(20,j);" for the curve at I=20 and "plot(y,Texact,y,T1)" to compare
the T1 curve and my Texact curve and I got the attached plot. I know it should
be a curve and not a flat line. Any help with this one? Thank you.
Chris W
________________________________
From: Doug Stewart-4 [via Octave] <address@hidden>
Sent: Monday, December 12, 2016 6:39 PM
To: darkstyle86
Subject: Re: Octave Error with Bounds
On Mon, Dec 12, 2016 at 3:50 PM, darkstyle86 <[hidden
email]</user/SendEmail.jtp?type=node&node=4681008&i=0>> wrote:
Great! That worked! Thank you. Now that I got using a constant value to
initialize temperatures out of the way, my real goal is to use a 1-D
temperature solution to initialize the temperatures everywhere for the 2-D
solution and plot the 1-D solution on the same graph as the 2-D solution.
1) To do the initialization, I'm using the following lines (similar lines to
what I provided earlier):
"% Initialization of temperatures using 1-D analytical solution
for i=1:M
for j=1:N T(i,j)=Texact; end
end"
this is just a guess but:
Would
for i=1:M
for j=1:N T(i,j)=Texact(j); end
end"
work?
As a reminder, my y vector is defined with"for j=1:N y(j)=dy*j; end", and
my 1-D solution Texact is defined as
"Texact=Tinf+(Q*(L^0.5)*besseli(0,(2*m*y.^0.5)))/(k*m*besseli(1,(2*m*L^0.5)));"
When I run the code, I'm getting the following error:
"error: Project_solver_w_areas: A(I,J,...) = X: dimensions mismatch
error: called from
Project_solver_w_areas at line 67 column 21"
Line 67 is the line "for j=1:N T(i,j)=Texact; end"
I'm sure the problem has to do with Texact only being based on a single
column y vector but I don't know how to get around this.
2) When I try to plot the 2-D solution T(i,j) (using the highlighted code
below), I'm getting the attached plot. I'm assuming this is because Octave is
plotting the curve (as a function of y(j)) for every value of i. Is this as
easy changing my plot function to only plot T(1,j) or whatever value of i I
want? If so, how do I do this (so that only one curve is shown)?
Thank you for your continued help, you're a lifesaver.
________________________________
From: Doug Stewart-4 [via Octave] <[hidden
email]</user/SendEmail.jtp?type=node&node=4681008&i=1>>
Sent: Monday, December 12, 2016 6:50 AM
To: darkstyle86
Subject: Re: Octave Error with Bounds
On Mon, Dec 12, 2016 at 1:52 AM, darkstyle86 <[hidden
email]</user/SendEmail.jtp?type=node&node=4681004&i=0>> wrote:
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] <[hidden
email]</user/SendEmail.jtp?type=node&node=4681004&i=1>>
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(j)=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
change this
for i=2:(M-1) T(i,j)=Tinf; end
to
for i=2:(M) 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
________________________________
If you reply to this email, your message will be added to the discussion below:
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==>.
NAML<http://octave.1599824.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
--
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.
_______________________________________________
Help-octave mailing list
[hidden email]</user/SendEmail.jtp?type=node&node=4681004&i=2>
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=4681004&i=3>
https://lists.gnu.org/mailman/listinfo/help-octave
________________________________
If you reply to this email, your message will be added to the discussion below:
http://octave.1599824.n4.nabble.com/Octave-Error-with-Bounds-tp4680987p4681004.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==>.
NAML<http://octave.1599824.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
2-D.pdf (11K) <http://octave.1599824.n4.nabble.com/attachment/4681006/0/2-D.pdf>
--
View this message in context:
http://octave.1599824.n4.nabble.com/Octave-Error-with-Bounds-tp4680987p4681006.html
Sent from the Octave - General mailing list archive at Nabble.com.
_______________________________________________
Help-octave mailing list
[hidden email]</user/SendEmail.jtp?type=node&node=4681008&i=2>
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=4681008&i=3>
https://lists.gnu.org/mailman/listinfo/help-octave
________________________________
If you reply to this email, your message will be added to the discussion below:
http://octave.1599824.n4.nabble.com/Octave-Error-with-Bounds-tp4680987p4681008.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==>.
NAML<http://octave.1599824.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
plot.pdf (7K)
<http://octave.1599824.n4.nabble.com/attachment/4681009/0/plot.pdf>
--
View this message in context:
http://octave.1599824.n4.nabble.com/Octave-Error-with-Bounds-tp4680987p4681009.html
Sent from the Octave - General mailing list archive at Nabble.com.