双变量之和

时间:2016-04-19 19:07:21

标签: c++ sum double

我有问题tyring做一些基本的补充。我不明白为什么J11的返回值为0而A11 * G11和A12 * G21的有限值。我知道它与变量类型有关 - 最有可能。非常感谢您的帮助。这是代码:

#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;
}

1 个答案:

答案 0 :(得分:4)

这必须为零:

J11 = A11 * G11 + A12 * G21;

因为A11 = -A12,你可以在这里看到:

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

和G11 = G21因为:

G11 = x
G21 = x

然而,我不知道你要用这​​段代码完成什么。