c++ - sum of double variables -
i have problem tyring basic addition. don't understand why returned value j11 0 while a11*g11 , a12*g21 have finite values. know has variable types - likely. appreciated. here 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); (size_t z = 0 ; z < 43 ; z++) { (size_t y = 0 ; y < 43 ; y++) { (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; }
this has zero:
j11 = a11 * g11 + a12 * g21;
because a11 = -a12 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 have no idea trying accomplish code.
Comments
Post a Comment