Home do-while loop starts at zero
Reply: 0

do-while loop starts at zero

user886
1#
user886 Published in April 21, 2018, 3:05 pm

What I'm aiming at is systematically increase the value of e1 from -1 to 0 in steps of 0.001. And with each value of e1, compute variable uNew with increasing values of the variable r by dr = 0.01 until r = 25;

But the energy keeps starting at zero instead of -1, And I can't figure out how to implement it, also, should I use two For loops?

 for(int i = 0; i < 1000 ; i++) {
     do {                                      
         e1 = e1 + 0.001;                  
     }while(e1 < 0 );                                                                        


      r = i*dr;
      uNew = 2*u1-u0+dr*dr*(2/r - 2*e1)*u0;            

      dr += 0.01;       
      u0 = u1;
      u1 = uNew;            
  }                                         
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.303181 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO