help-octave
[Top][All Lists]

Re: REALLY WEIRED ISSUE

 From: Doug Stewart Subject: Re: REALLY WEIRED ISSUE Date: Tue, 26 Feb 2008 15:10:44 -0500 User-agent: Thunderbird 1.5.0.14 (Windows/20071210)

Gaurav Malhotra wrote:

Hi All,

This is my first post to this mailing list and I am trying to use octave to promote it at my work for adoption as primary for scientific stuff.
ALSO APOLOGIES FOR A REALLY LONG MESSAGE.

My main issue is, Below is the code I wrote in octave(a rather simple one) but it dows not give me the correct answer. I have debugged this several time and have tried to do as many things I could think of but the solution I get is inaccurate. Than I wrote exactly the same code in C/C++ and got the right solution in first go.

*Could you all help me with what's wrong in the code as I really need "octave" to work for me cause it's so much better than using C/C++ for such stuff. *FYI, I am using Octave 3.0 on windows and SciTe as my editor.

Below is my code: -

+++++++++++++++++++++++++++

# Function Definition here

function GValueTopWall = GFactorTopWall(x, y, n, e, z)
a = y - n;
b = x - e;
asquared = a * a;
bsquared = b * b;
zsquared = z * z;
GValueTopWall = 0;
g1 = (a * sqrt(bsquared + zsquared));
g2 = atan( ( a / sqrt(bsquared + zsquared)) );
g3 = (b * sqrt(asquared + zsquared));
g4 = atan( (b / sqrt(asquared + zsquared)) );
g5 = zsquared / 2;
g6 = log(bsquared + asquared + zsquared);
g7 = 2 * pi;
GValueTopWall = ((g1 * g2) + (g3 * g4) - (g5 * g6))/g7;
return;
endfunction

# Actual Code Starts Here
# Assumptions: -
# Furnace Depth/Length = 30 ft
# Furnace Height = 8 ft
# Furnace Width = 10 ft
# Strip width min = 36in/3ft max = 62in/5.166ft with 2in/0.16ft step

clc

y = [0, 30];
n = [0, 30];
e = [0, 30];
z = 4;
sum = 0;
minwidthinch = 36;
maxwidthinch = 62;
furnacewidthinch = 120;
loop = minwidthinch;

do
x(1) = (furnacewidthinch - loop) / (2 * 12);
x(2) = (((furnacewidthinch - loop) / 2) + loop) / 12;
area = (x(2) - x(1)) * (y(2) - y(1));
sum = 0;
for l = 1:2
for k = 1:2
for j = 1:2
for i = 1:2
minusone = (-1)^(i + j + k + l);
GValueTopWall = GFactorTopWall(x(i), y(j), n(k), e(l), z);
sum = sum + (minusone * GValueTopWall)/area;
endfor
endfor
endfor
endfor
FValueTopWall = sum;
printf("View Factor for %d strip width = %f \n", loop, FValueTopWall);
loop = loop + 2;
until (loop > maxwidthinch)

++++++++++++++++++++++++++++++++++++++

Output of this code: -

>C:\Program Files\Octave\bin\octave.exe -q "view-factors-topwall.m"
- Use `pkg list' to see a list of installed packages.
- SciTE editor installed. Use `edit' to start the editor.
- MSYS shell available (C:\Program Files\Octave\msys).
- Graphics backend: jhandles.

View Factor for 36 strip width = 0.784004
View Factor for 38 strip width = 0.783552
View Factor for 40 strip width = 0.783074
View Factor for 42 strip width = 0.782569
View Factor for 44 strip width = 0.782037
View Factor for 46 strip width = 0.781479
View Factor for 48 strip width = 0.780893
View Factor for 50 strip width = 0.780279
View Factor for 52 strip width = 0.779637
View Factor for 54 strip width = 0.778967
View Factor for 56 strip width = 0.778269
View Factor for 58 strip width = 0.777542
View Factor for 60 strip width = 0.776786
View Factor for 62 strip width = 0.776000
>Exit code: 0

Correct Solution: -

View factor for 36 inch strip width = 0.697687
View factor for 38 inch strip width = 0.696786
View factor for 40 inch strip width = 0.695833
View factor for 42 inch strip width = 0.694826
View factor for 44 inch strip width = 0.693767
View factor for 46 inch strip width = 0.692653
View factor for 48 inch strip width = 0.691485
View factor for 50 inch strip width = 0.690262
View factor for 52 inch strip width = 0.688984
View factor for 54 inch strip width = 0.687649
View factor for 56 inch strip width = 0.686257
View factor for 58 inch strip width = 0.684808
View factor for 60 inch strip width = 0.6833
View factor for 62 inch strip width = 0.681735

CONFIDENTIALITY NOTICE

This e-mail contains privileged and confidential information which is the
property of Nucor, intended only for the use of the intended recipient(s).
Unauthorized use or disclosure of this information is prohibited. If you
are not an intended recipient, please immediately notify Nucor and destroy
any copies of this email.  Receipt of this e-mail shall not be deemed a
waiver by Nucor of any privilege or the confidential nature of the information.

------------------------------------------------------------------------

_______________________________________________
Help-octave mailing list