| 1 | 1/1 | 返回列表 |
| 查看: 961 | 回復(fù): 0 | ||
咔咔咔咔新蟲 (初入文壇)
|
[求助]
二維ising模型蒙特卡洛程序出錯(cuò),求指點(diǎn)
|
|
#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 } } void GetInitial() { int k,m; for(k=0;k for(m=0;m } } void CaculateFirstMagnet() { int i,j; int iMagnet=0; for(i=0;i for(j=0;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 執(zhí)行 cl.exe 時(shí)出錯(cuò). ising.obj - 1 error(s), 0 warning(s) 怎么辦 |
找到一些相關(guān)的精華帖子,希望有用哦~
| 1 | 1/1 | 返回列表 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 0805 316求調(diào)劑 +4 | 大雪深藏 2026-03-18 | 4/200 |
|
|---|---|---|---|---|
|
[考研] 306求0703調(diào)劑一志愿華中師范 +10 | 紙魚ly 2026-03-21 | 11/550 |
|
|
[考研] 材料292調(diào)劑 +8 | 橘頌思美人 2026-03-23 | 8/400 |
|
|
[考研] 307求調(diào)劑 +3 | 余意卿 2026-03-21 | 6/300 |
|
|
[考研]
|
13659058978 2026-03-24 | 4/200 |
|
|
[考研] 材料與化工328分調(diào)劑 +4 | 。,。,。,。i 2026-03-23 | 4/200 |
|
|
[考研] 335求調(diào)劑 +4 | yuyu宇 2026-03-23 | 5/250 |
|
|
[考研] 341求調(diào)劑(一志愿湖南大學(xué)070300) +5 | 番茄頭--- 2026-03-22 | 6/300 |
|
|
[考研] 333求調(diào)劑 +6 | 87639 2026-03-21 | 10/500 |
|
|
[考研] 291求調(diào)劑 +5 | 孅華 2026-03-22 | 5/250 |
|
|
[考研] 求調(diào)劑一志愿海大,0703化學(xué)學(xué)碩304分,有大創(chuàng)項(xiàng)目,四級(jí)已過(guò) +6 | 幸運(yùn)哩哩 2026-03-22 | 10/500 |
|
|
[考研] 一志愿華中農(nóng)業(yè)071010,總分320求調(diào)劑 +5 | 困困困困坤坤 2026-03-20 | 6/300 |
|
|
[考研] 一志愿中南化學(xué)(0703)總分337求調(diào)劑 +9 | niko- 2026-03-19 | 10/500 |
|
|
[考研] 求調(diào)劑院校信息 +6 | CX 330 2026-03-21 | 6/300 |
|
|
[考研] 求調(diào)劑 +7 | Auroracx 2026-03-22 | 7/350 |
|
|
[考研] 285求調(diào)劑 +6 | ytter 2026-03-22 | 6/300 |
|
|
[考研]
|
Grand777 2026-03-21 | 3/150 |
|
|
[考研] 材料學(xué)學(xué)碩080502 337求調(diào)劑-一志愿華中科技大學(xué) +4 | 順順順mr 2026-03-18 | 5/250 |
|
|
[考研] 一志愿 西北大學(xué) ,070300化學(xué)學(xué)碩,總分287,雙非一本,求調(diào)劑。 +3 | 晨昏線與星海 2026-03-18 | 3/150 |
|
|
[考研]
|
不想起名字112 2026-03-19 | 3/150 |
|