*Here it is, inherently the same code I just made few changes to make
some variables to be input by user, Thanks a ton for your help.*
#include <iostream>
#include <math.h>
#include <fstream>
double GFactorTopWall(double x, int y, int n, int e, int z)
{
double PI = 3.14159265;
double a = (y - n);
double b = (x - e);
double asquared = a * a;
double bsquared = b * b;
double zsquared = z * z;
double g1 = (a * sqrt(bsquared + zsquared));
double g2 = atan( (a / sqrt(bsquared + zsquared)));
double g3 = (b * sqrt(asquared + zsquared));
double g4 = atan( (b / sqrt(asquared + zsquared)));
double g5 = zsquared / 2;
double g6 = log(bsquared + asquared + zsquared);
double g7 = 2 * PI;
double GValue;
GValue = ((g1 * g2) + (g3 * g4) - (g5 * g6))/g7;
return GValue;
}
int main()
{
int y[2] = {0, 30};
int n[2] = {0, 30};
int e[2] = {0, 10};
int z = 4;
double x[2];
double minusone;
double FValueTopWall;
double GValueTopWall;
double sum = 0;
int minwidthinch = 36;
int maxwidthinch = 62;
int furnacewidthinch = 120;
std::cout << "\n\n Calulating view factors and writing them to
a file too ##### \n\n";
std::ofstream FValueFile("f-top-wall.txt");
double loop = minwidthinch;
do
{
x[0] = (furnacewidthinch - loop) / (2 * 12);
x[1] = (((furnacewidthinch - loop)/2) + loop) / 12;
double area = (x[1] - x[0]) * (y[1] - y[0]);
std::cout << "\nFor a Strip Width of " << loop << "
inches : - \n";
std::cout <<
"+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+\n\n";
FValueFile << "\nFor a Strip Width of " << loop << "
inches : - \n";
FValueFile <<
"+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+\n\n";
sum = 0;
for (int l = 0 ; l < 2; ++l)
{
for (int k = 0; k < 2; ++k)
{
for (int j = 0; j < 2; ++j)
{
for (int i = 0; i < 2;
++i)
{
minusone =
pow((double)-1, ((i+1) + (j+1) + (k+1) + (l+1)));
GValueTopWall
= GFactorTopWall(x[i], y[j], n[k], e[l], z);
sum +=
(minusone * GValueTopWall);
}
}
}
}
FValueTopWall = sum/area;
std::cout << "Top Wall View-factor @ y(" <<
y[0] << "," << y[1] << ") = " << FValueTopWall << "\n";
FValueFile << "Top Wall View-factor @ y(" <<
y[0] << "," << y[1] << ") = " << FValueTopWall << "\n";
loop = loop + 2;
}
while (loop <= maxwidthinch);
FValueFile.close();
std::cout << "\n";
return 0;
}
*Doug Stewart <address@hidden>*
02/26/2008 03:10 PM
To
Gaurav Malhotra <address@hidden>
cc
address@hidden
Subject
Re: REALLY WEIRED ISSUE
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
>
>
>
> Thanks in advance
> 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
> address@hidden
> https://www.cae.wisc.edu/mailman/listinfo/help-octave
I have looked at this and tested atan2 instead of atan and I tried log10
instead of log but these did not help.
If you send me your "C" code I might be able to see what is different.
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.