Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
algo<-function(T,N){
K<-1
M<-matrix(nrow = N, ncol = N, data = 1)
M1<-matrix(nrow = N, ncol = N, data = -1)
while (compareEqual(M,M1)=='FALSE'){
M<-matrix(nrow = N, ncol = N, data = 1)
M1<-matrix(nrow = N, ncol = N, data = -1)
for(l in -K:-1){
i<-0
j<-0
i = sample(1:N,1,replace=TRUE)
j = sample(1:N,1,replace=TRUE)
if(i==1){
	if(j==1){
		Z<-exp((2/T)*M[1,1]*(M[1,2]+M[2,1]));
		Z1<-exp((2/T)*M1[1,1]*(M1[1,2]+M1[2,1]));
cat("---------------------------------------------------------------------------1\n")
 
		}
	if(j==N){
		Z<-exp((2/T)*M[1,N]*(M[1,N-1]+M[2,N]));
		Z1<-exp((2/T)*M1[1,N]*(M1[1,N-1]+M1[2,N]));
cat("---------------------------------------------------------------------------2\n")
		}
	else{
		Z<-exp((2/T)*M[i,j]*(M[i,j-1]+M[i,j+1]+M[i+1,j]));
		Z1<-exp((2/T)*M1[i,j]*(M1[i,j-1]+M1[i,j+1]+M1[i+1,j]));
cat("---------------------------------------------------------------------------3\n")
		}
	}
 
if(i==N){
	if(j==1){
		Z<-exp((2/T)*M[N,1]*(M[N-1,1]+M[N,2]));
		Z1<-exp((2/T)*M1[N,1]*(M1[N-1,1]+M1[N,2]));
cat("---------------------------------------------------------------------------4\n")
		}
	if(j==N) {
		Z<-exp((2/T)*M[N,N]*(M[N,N-1]+M[N-1,N]));
		Z1<-exp((2/T)*M1[N,N]*(M1[N,N-1]+M1[N-1,N]));
	cat("---------------------------------------------------------------------------5\n")
		}
	else{
		Z<-exp((2/T)*M[i,j]*(M[i-1,j]+M[i,j+1]+M[i,j-1]));
		Z1<-exp((2/T)*M1[i,j]*(M1[i-1,j]+M1[i,j+1]+M1[i,j-1]));
	cat("---------------------------------------------------------------------------6\n")
		}
 
	}
else{
	Z<-exp((2/T)*M[i,j]*(M[i-1,j]+M[i+1,j]+M[i,j+1]+M[i,j-1]));
	Z1<-exp((2/T)*M1[i,j]*(M1[i-1,j]+M1[i+1,j]+M1[i,j+1]+M1[i,j-1]));
	cat("---------------------------------------------------------------------------7\n")
	}
 
V<-runif(1,0,1)
Y<-V-Z
Y1<-V-Z1
if(Y<0){
	M[i,j]<-(-1);
cat("---------------------------------------------------------------------------8\n")
	}
else{
	M[i,j]<-1;
cat("---------------------------------------------------------------------------9\n")
	}
 
if(Y1<0){
	M1[i,j]<-(-1);
cat("---------------------------------------------------------------------------10\n")
	}
else{
	M1[i,j]<-1;
cat("---------------------------------------------------------------------------11\n")
	}
}
cat(k,"\n");
K<-2*K;
cat(k,"\n");
}
M
}
Voilà mon code, l'erreur: l'argument est de longueur nulle est au niveau du test de Y (if (Y<0)
Je n'arrive pas à voir pourquoi la valeur nulle est affectée à Y et pourquoi il y a un dépassement dans ma matrice. Si vous pouviez m'aider ça serait génial. Merci d'avance

Pour la fonction compareEqual j'ai téléchargé le package compare.