okay, i'm trying compute infinite sum using loop instead of while loop, , darn code isn't working , i'm not sure why. 2 "i got here"'s once , nothing. :\
does know why code isn't working , looks freezes or hangs? loops should end way made them, right? here's current problem code
check=0; cerr << "i got here" << endl; (int m=1;m<m+1;m++) { cerr << "i got here" << endl; (int n=1;n<n+1;n++) { if (check==0) { anaphi[i][j][k]=1.0/(m*m*m*n*n*n) *cos(k*deltat*sqrt(5.0)*pi/4.0 *sqrt(m*m+4.0*n*n)) *sin(m*pi*i*h/4.0) *sin(n*pi*j*h/2.0); check=1; } else { anaphi[i][j][k]= anaphi[i][j][k] +1.0/(m*m*m*n*n*n) *cos(k*deltat*sqrt(5.0)*pi/4.0 *sqrt(m*m+4.0*n*n)) *sin(m*pi*i*h/4.0) *sin(n*pi*j*h/2.0); } } } }
i tested code , code doesn't work!
#include <iostream> #include <cmath> using namespace std; int main() { int b=0; (int m=1;m<m+1;m=m+2) { b=cos(b)+sqrt(b); } cout << b << endl; return 0; }
i see couple of issues.
if(check=0)
set check 0.because use
n= n+2
, not ever break. because @ point n = 0x7ffffffe (highest positive number) , in case n+1 > n. wraps 0x80000000 (the negative signed int, still even) , n+1 still > n. if able n = 0x7fffffff, n + 1 less n due integer wrap around.there not seem other way break out of loops meeting coditions set.
Comments
Post a Comment