user147813
user147813

Reputation: 67

sum of double variables

I have problem tyring to do some basic addition. I don't understand why the returned value for J11 is 0 while A11*G11 and A12*G21 have finite values. I know it has to do with variable types - most likely. Your help is much appreciated. Here is the code:

#include <vector>
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <set>

using namespace std;

void simple() 
{
double G11,G12,G13,G21,G22,G23,G31,G32;
double G33,G41,G42,G43,G51,G52,G53,G61;
double G62,G63,G71,G72,G73,G81,G82,G83;
double J11;
double xx,yy,zz;
double A11,A12;
vector<double> xcoor;
vector<double> ycoor;
vector<double> zcoor;
double G1=1/sqrt(3);
double G2=-1/sqrt(3);

    xcoor.push_back(G1);
    xcoor.push_back(G2);
    xcoor.push_back(G1);
    xcoor.push_back(G2);
    xcoor.push_back(G1);
    xcoor.push_back(G2);
    xcoor.push_back(G1);
    xcoor.push_back(G2);

    ycoor.push_back(G1);
    ycoor.push_back(G2);
    ycoor.push_back(G2);
    ycoor.push_back(G1);
    ycoor.push_back(G1);
    ycoor.push_back(G2);
    ycoor.push_back(G2);
    ycoor.push_back(G1);

    zcoor.push_back(G2);
    zcoor.push_back(G2);
    zcoor.push_back(G2);
    zcoor.push_back(G2);
    zcoor.push_back(G1);
    zcoor.push_back(G1);
    zcoor.push_back(G1);
    zcoor.push_back(G1);


    for (size_t z = 0 ; z < 43 ; z++) {
        for (size_t y = 0 ; y < 43 ; y++) {
            for (size_t x = 0 ; x < 43 ; x++) {                         

                G11=x;
                G12=y;
                G13=z;
                G21=x;
                G22=y+1.;
                G23=z;
                G31=x+1.;
                G32=y+1.;
                G33=z;
                G41=x+1.;
                G42=y;
                G43=z;
                G51=x;
                G52=y;
                G53=z+1.;
                G61=x;
                G62=y+1.;
                G63=z+1.;
                G71=x+1.;
                G72=y+1.;
                G73=z+1.;
                G81=x+1.;
                G82=y;
                G83=z+1.;

            for(size_t t = 0 ; t < 8 ; t++){

                 xx = xcoor[t];
                 yy = ycoor[t];
                 zz = zcoor[t];

                A11=(-1./8.)*(1-yy)*(1-zz);         
                A12=(1./8.)*(1-yy)*(1-zz);

                J11 = A11 * G11 + A12 * G21;

                cout<<J11<<endl;

                }
            }
        }
    }
}



int main ()
{

    simple();
    cout << "Computation done." << endl;

    return 0;
}

Upvotes: 0

Views: 450

Answers (1)

Frank Puffer
Frank Puffer

Reputation: 8215

This has to be zero:

J11 = A11 * G11 + A12 * G21;

because A11 = -A12 as you can see here:

A11=(-1./8.)*(1-yy)*(1-zz);         
A12=(1./8.)*(1-yy)*(1-zz);

and G11 = G21 because of:

G11 = x
G21 = x

Nevertheless I have no idea what you are trying to accomplish with this code.

Upvotes: 4

Related Questions