±±¾©Ê¯ÓÍ»¯¹¤Ñ§Ôº2026ÄêÑо¿ÉúÕÐÉú½ÓÊÕµ÷¼Á¹«¸æ
²é¿´: 963  |  »Ø¸´: 0

ßÇßÇßÇßÇ

гæ (³õÈëÎÄ̳)

[ÇóÖú] ¶þάisingÄ£ÐÍÃÉÌØ¿¨Âå³ÌÐò³ö´í£¬ÇóÖ¸µã

#include
#include
#include
#include
#define L 150                        
#define preN   100000               
#define lateN 5100000               
#define deltaN (lateN-preN)         
double recordEnergy[deltaN];         
int recordMagnet[deltaN];            
int lattice[L][L];                  
int temp[L][L];                     
double energy;                       
int magnet;                          
double T;                           
struct CX                           
{
    double C;
    double X;
};

void InitialLattice();
void SaveInitial();
void GetInitial();
void CaculateFirstMagnet();
void CaculateFirstEnergy();
void GenerateNext();
struct CX Caculate_C_and_X();

int main()
{
int i;
    struct CX cx[200];
    FILE *ft,*fx,*fc;
ft=fopen("T.txt","w";
fx=fopen("X.txt","w";
fc=fopen("C.txt","w";
    srand(time(NULL));

T = 1.0;
for(i=0;T<4.0;i++)
{
  InitialLattice();
  cx=Caculate_C_and_X();
  fprintf(ft,"%f\n",T);
  fprintf(fx,"%f\n",cx.X);
  fprintf(fc,"%f\n",cx.C);
  printf("T=%f ",T);
  printf("  X=%f ",cx.X);
  printf("  C=%f\n",cx.C);
        T = T+0.05;
}

fclose(ft);
fclose(fx);
fclose(fc);
return 0;
}

void InitialLattice()                             
{                                                
    int i,j;                                    
    for(i=0;i     {
        for(j=0;j   {
   if((rand()%10)>5) lattice[j]=1;
   else              lattice[j]=1;     
        }
    }
}
void SaveInitial()                                 
{                                                  
int k,m;                                       
for(k=0;k {
  for(m=0;m    temp[k][m]=lattice[k][m];
}
}
void GetInitial()                                 
{                                                  
int k,m;                                       
for(k=0;k {
  for(m=0;m    lattice[k][m]=temp[k][m];

}
}
void CaculateFirstMagnet()                          
{
    int i,j;
    int iMagnet=0;
    for(i=0;i     {
        for(j=0;j    iMagnet += lattice[j];
    }
    magnet = iMagnet;
}
void CaculateFirstEnergy()                          
{

    double dEnergy = 0.0;
int up,down,right,left,px,py;
for(px=0;px {
  for(py=0;py   {
   up = (L+px-1)%L;
   down = (px+1)%L;
   right = (L+py-1)%L;
   left = (py+1)%L;
   dEnergy += 0.5*lattice[px][py]*(lattice[up][py]+lattice[down][py]+lattice[px][right]+lattice[px][left]);
  }
}

energy = dEnergy;
}
void GenerateNext()                                    
{
    int px,py;
    int dE,sum;
int up,down,right,left;
px = rand()%L;
    py = rand()%L;

up = (L+px-1)%L;
down = (px+1)%L;
right = (L+py-1)%L;
left = (py+1)%L;

sum = (lattice[px][py])*(lattice[up][py]+lattice[down][py]+lattice[px][right]+lattice[px][left]);
switch(sum)
{
case 4: dE= 8; break;
case 2: dE= 4; break;
case 0: dE= 0; break;
case -2: dE= -4; break;
case -4: dE= -8; break;
default: printf("---Erro!---\n"; break;
}

    if( dE>0 )                                             
    {
        if((rand()*1.0/RAND_MAX) <= exp((-1.0)*dE/T))
  {
   lattice[px][py] = -lattice[px][py];
   magnet += 2*lattice[px][py];                  
   energy += dE;                                 
  }

    }
    else
    {
  lattice[px][py] = -lattice[px][py];
  magnet += 2*lattice[px][py];                       
  energy += dE;                                      
    }

}
struct CX Caculate_C_and_X()                              
{
    struct CX cx;
    int i;
    double AvgEnergy=0.0;
    double AvgSquareEnergy=0.0;
    double AvgMagnet=0.0;
    double AvgSquareMagnet=0.0;

CaculateFirstMagnet();                                 
CaculateFirstEnergy();                                 

    for(i=0; i     {
        GenerateNext();                                      
        if(i>=preN)                                          
        {
            recordEnergy[i-preN] = energy;                  
            recordMagnet[i-preN] = magnet;                  
  }
}

    for(i=0;i     {
        AvgEnergy += (double)recordEnergy/deltaN;
        AvgSquareEnergy += (double)recordEnergy*recordEnergy/deltaN;
        AvgMagnet += (double)recordMagnet/deltaN;
        AvgSquareMagnet += (double)recordMagnet*recordMagnet/deltaN;
    }

    cx.C = (AvgSquareEnergy - AvgEnergy*AvgEnergy)/T/T;      
    cx.X = (AvgSquareMagnet - AvgMagnet*AvgMagnet)/T;
  
    return cx;
}



:\microsoft visual studio\myprojects\ising\ising.cpp(44) : error C2440: '=' : cannot convert from 'struct CX' to 'struct CX [200]'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
d:\microsoft visual studio\myprojects\ising\ising.cpp(46) : error C2228: left of '.X' must have class/struct/union type
d:\microsoft visual studio\myprojects\ising\ising.cpp(47) : error C2228: left of '.C' must have class/struct/union type
d:\microsoft visual studio\myprojects\ising\ising.cpp(49) : error C2228: left of '.X' must have class/struct/union type
d:\microsoft visual studio\myprojects\ising\ising.cpp(50) : error C2228: left of '.C' must have class/struct/union type
d:\microsoft visual studio\myprojects\ising\ising.cpp(67) : error C2440: '=' : cannot convert from 'const int' to 'int [150]'
        There are no conversions to array types, although there are conversions to references or pointers to arrays
d:\microsoft visual studio\myprojects\ising\ising.cpp(68) : error C2440: '=' : cannot convert from 'const int' to 'int [150]'
        There are no conversions to array types, although there are conversions to references or pointers to arrays
d:\microsoft visual studio\myprojects\ising\ising.cpp(98) : error C2297: '+=' : illegal, right operand has type 'int [150]'
d:\microsoft visual studio\myprojects\ising\ising.cpp(187) : error C2440: 'type cast' : cannot convert from 'double [5000000]' to 'double'
        There is no context in which this conversion is possible
d:\microsoft visual studio\myprojects\ising\ising.cpp(188) : error C2440: 'type cast' : cannot convert from 'double [5000000]' to 'double'
        There is no context in which this conversion is possible
d:\microsoft visual studio\myprojects\ising\ising.cpp(189) : error C2440: 'type cast' : cannot convert from 'int [5000000]' to 'double'
        There is no context in which this conversion is possible
d:\microsoft visual studio\myprojects\ising\ising.cpp(190) : error C2440: 'type cast' : cannot convert from 'int [5000000]' to 'double'
        There is no context in which this conversion is possible
Ö´ÐÐ cl.exe ʱ³ö´í.

ising.obj - 1 error(s), 0 warning(s)
Ôõô°ì
»Ø¸´´ËÂ¥
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

ÖÇÄÜ»úÆ÷ÈË

Robot (super robot)

ÎÒÃǶ¼°®Ð¡Ä¾³æ

ÕÒµ½Ò»Ð©Ïà¹ØµÄ¾«»ªÌû×Ó£¬Ï£ÍûÓÐÓÃŶ~

¿ÆÑдÓСľ³æ¿ªÊ¼£¬ÈËÈËΪÎÒ£¬ÎÒΪÈËÈË
Ïà¹Ø°æ¿éÌø×ª ÎÒÒª¶©ÔÄÂ¥Ö÷ ßÇßÇßÇßÇ µÄÖ÷Ìâ¸üÐÂ
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[¿¼ÑÐ] Ò»Ö¾Ô¸0817»¯Ñ§¹¤³ÌÓë¼¼Êõ£¬Çóµ÷¼Á +7 ÎÒ²»ÊÇÖ»Òò 2026-04-02 8/400 2026-04-03 00:15 by ÓêÌì³ÅÉ¡
[¿¼ÑÐ] 326Çóµ÷¼Á +8 áÌáÌ×Ð 2026-04-02 8/400 2026-04-02 23:00 by Î޼ʵIJÝÔ­
[¿¼ÑÐ] Ò»Ö¾Ô¸Ö£ÖÝ´óѧ²ÄÁÏÓ뻯¹¤085600£¬Çóµ÷¼Á +10 ³ÔµÄ²»ÉÙ 2026-04-02 10/500 2026-04-02 22:58 by Âí¶ù¿ì¿ìµØÅÜ
[¿¼ÑÐ] 322Çóµ÷¼Á£ºÒ»Ö¾Ô¸ºþÄÏ´óѧ ²ÄÁÏÓ뻯¹¤£¨085600£©£¬ÒѹýÁù¼¶¡£ +12 XXСµË 2026-03-29 13/650 2026-04-02 21:39 by °ÙÁéͯ888
[¿¼ÑÐ] 315·Ö 085602 Çóµ÷¼Á +10 26¿¼ÑÐÉϰ¶°æ26 2026-04-02 10/500 2026-04-02 20:45 by dongzh2009
[¿¼ÑÐ] ÄÜÔ´¶¯Á¦ µ÷¼Á +3 ²»ÆÆ²»Á¢0 2026-04-02 3/150 2026-04-02 12:46 by ffffjjjj
[¿¼ÑÐ] ¼ÆËã»ú265¿çµ÷»·¾³ +5 Yumeng_6 2026-03-27 5/250 2026-04-02 10:54 by guanxin1001
[¿¼ÑÐ] Ò»Ö¾Ô¸9³õÊÔ366 ±¾Ë«·ÇÇóµ÷¼Á +4 ÔËÆøÀ´µÃÈôÓÐËÆÎ 2026-04-02 4/200 2026-04-02 09:56 by guanxin1001
[¿¼ÑÐ] Ò»Ö¾Ô¸Äϲý´óѧ324Çóµ÷¼Á +12 hanamiko 2026-03-27 12/600 2026-04-01 22:34 by ÔËÆøyunqi
[¿¼ÑÐ] 070300»¯Ñ§279Çóµ÷¼Á +15 ¹þ¹þ¹þ^_^ 2026-03-31 17/850 2026-04-01 21:37 by ¸øÄãÄã×¢ÒâÐÝÏ¢
[¿¼ÑÐ] ʳƷѧ˶362Çóµ÷¼Á +3 xuanxianxian 2026-04-01 3/150 2026-04-01 21:05 by °¡Àî999
[¿¼ÑÐ] ²ÄÁÏר˶322·Ö +9 ¹þ¹þ¹þºðºðºð¹þ 2026-04-01 9/450 2026-04-01 14:30 by Î޼ʵIJÝÔ­
[¿¼ÑÐ] 262Çóµ÷¼Á +9 ÀøÖ¾Ò»¶¨·¢ÎÄÕ 2026-03-31 10/500 2026-04-01 12:22 by sunshine0013
[¿¼ÑÐ] ²ÄÁÏÓ뻯¹¤272Çóµ÷¼Á +25 °¢Ë¹µÙ·Ò2004 2026-03-28 25/1250 2026-03-31 16:27 by hypershenger
[¿¼ÑÐ] 322Çóµ÷¼Á +10 ËÎÃ÷ÐÀ 2026-03-27 10/500 2026-03-30 18:47 by 544594351
[¿¼ÑÐ] Çóµ÷¼Á +7 ÕùÈ¡¾Åµã˯ 2026-03-28 8/400 2026-03-28 21:07 by ÕùÈ¡¾Åµã˯
[¿¼ÑÐ] 283Çóµ÷¼Á +3 A child 2026-03-28 3/150 2026-03-28 15:41 by ms629
[¿¼ÑÐ] ²ÄÁÏÓ뻯¹¤£¨0856£©304ÇóBÇøµ÷¼Á +8 Çñgl 2026-03-27 8/400 2026-03-28 12:42 by ÌÆãå¶ù
[¿¼ÑÐ] 265Çóµ÷¼Á +8 Сľ³æ085600 2026-03-27 8/400 2026-03-27 22:16 by Î޼ʵIJÝÔ­
[¿¼ÑÐ] Ò»Ö¾Ô¸¼ª´ó071010£¬316·ÖÇóµ÷¼Á +3 xgbiknn 2026-03-27 3/150 2026-03-27 10:36 by guoweigw
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û