Exemplo n.º 1
0
  bool run(){
  for(j=0;j<MAX_ITER_RK;j++) {
    //Avoid going out of x interval
    if (x+h >xn) {
      h = xn-x;
      j = MAX_ITER_RK;
    }

    //Compute k1, k2, k3, k4
    for(i=0;i<m;i++)
      k1[i] = h*unit->f(i, x, y);
    for(i=0;i<m;i++)
      y_tmp[i] = y[i]+k1[i]/2.0;
    for(i=0;i<m;i++)
      k2[i] = h*unit->f(i, x+h/2.0, y_tmp);
    for(i=0;i<m;i++)
      y_tmp[i] = y[i]+k2[i]/2.0;
    for(i=0;i<m;i++)
      k3[i] = h*unit->f(i, x+h/2.0, y_tmp);
    for(i=0;i<m;i++)
      y_tmp[i] = y[i]+k3[i];
    for ( i = 0 ; i < m ; i++ )
      k4[i] = h*unit->f ( i , x+h , y_tmp );
    //Compute the new y
    for(i=0;i<m;i++)
      y[i]+=(k1[i]+2*k2[i]+2*k3[i]+k4[i])/6.0;
    x += h;
  }

  if ( x < xn-EPS ) {// MODIF SEB (le EPS)
    success=false;
    
    // cout.setf(ios::fixed);
    // cout << setprecision(12);
    // cout << "x=" << x << " < xn=" << xn << " diff=" << xn-x << endl;
  }

  return success;
}
Exemplo n.º 2
0
  bool run(){
   for (i=1; i<MAX_ITER_BISSECTION; i++)
   {
      xm=(x1+x2)/2;
      // if(DEBUG) cout<<endl<<x1<<"  "<<xm<<"  "<<x2;
      if (fabs(x1-x2)/fabs(xm) < TOL_BISSECTION)
      {
         i=MAX_ITER_BISSECTION;
         OK=true;
      }
      else
      {
         f1 = unit->f(x1);
         fm = unit->f(xm);
         f2 = unit->f(x2);
         if (f1*fm < 0.0) x2 = xm;
         if (fm*f2 < 0.0) x1 = xm;
      }
   }
   // if (DEBUG) system("pause");
   return OK;
}
Exemplo n.º 3
0
    int f(int a, int b) {
		return engine.f(a, b);
	}