Ejemplo n.º 1
0
static int
MATGEN(REAL a[], int lda, int n, REAL b[], REAL *norma)
{
	int		i;
	int		init[4];
	int		j;
	REAL	value;

	init[0] = 1;
	init[1] = 2;
	init[2] = 3;
	init[3] = 1325;
	*norma = LP_ZERO;
	for (j = 0; j < n; j++) {
		for (i = 0; i < n; i++) {
#ifdef FPS_LAPA_UNK
			a[lda*j+i] =
			    (i < j) ? (double)(i+1) : (double)(j+ALPHA);
			if (fabs(a[lda*j+i]) > *norma)
				*norma = fabs(a[lda*j+i]);
			} /* i */
#else
			value = (REAL) dran(init) - 0.5;
			a[lda * j + i] = value;
			value = fabs(value);
			if (value > *norma) {
				*norma = value;
			}
		} /* i */
#endif /* FPS_LAPA_UNK */
	} /* j */
Ejemplo n.º 2
0
void pos_from_monte_carlo(int n,double step, Vec *L, double t, Vec* pos)
{
  int i,j;
  Vec spos,dist;
  double dU;
  double chProb,Udiff;

	//printf("pos3! %.3f\n", pos[3].x);
  
  for(i=0; i<n; i++) {
    spos.x = inrange(pos[i].x + dran_sign()*step,L->x);
    spos.y = inrange(pos[i].y + dran_sign()*step,L->y);
    dU = 0.0;
		for(j=0; j<n; j++) 
			if(i!=j)
				dU += pair_interaction(dist2(L, &spos, pos+j, &dist)) - pair_interaction(dist2(L, pos+i, pos+j, &dist));

    chProb = fmin(1,exp(-dU/t));
    if(dran() < chProb) {
      pos[i].x = spos.x;
      pos[i].y = spos.y;
    }
  }
    
}
Ejemplo n.º 3
0
void pos_from_monte_carlo(int n,double step, Vec *L, double t, double noise, double alpha, double deltat, Vec* pos, Vec* force)
{
  int i,j;
  Vec spos,dist;
  double Ur,Ui;
  double chProb,Udiff;
  
  for(i=0; i<n; i++) {
    spos.x = pos[i].x + dran_sign()*step;
    spos.y = pos[i].y + dran_sign()*step;
    Ur = Ui = 0.0;
    for(j=0; j<n; j++) {
      Ur += pair_interaction(dist2(L, pos+i, pos+j, &dist));
      Ui += pair_interaction(dist2(L, &spos, pos+j, &dist));
    }
    Udiff = Ui-Ur;
    chProb = fmin(1,exp(-Udiff/t));
    if(dran() < chProb) {
      pos[i].x = spos.x;
      pos[i].y = spos.x;
    }
  }
    
}