Enderounet
Messages postés29Date d'inscriptionmardi 2 août 2005StatutMembreDernière intervention30 août 2005
-
18 août 2005 à 14:04
Enderounet
Messages postés29Date d'inscriptionmardi 2 août 2005StatutMembreDernière intervention30 août 2005
-
22 août 2005 à 10:40
Salut,
j'ai cet algo en Basic et je l'ai traduit en java, mais je n'obtient pas les memes résultats.
Si qqun voit une erreur ou qque chose qui ne va pas, je le remercie d'avance.
Basic :
INPUT " ALPHA "; x(1)
LOCATE 25, 25
INPUT " BETA "; x(2)
LOCATE 27, 25
INPUT " GAMMA "; x(3)
4150 x(4) = .1
x(5) = .1
x(6) = -2
x(7) = 9
x(8) = 7
x(9) = 2
v(1) = .01
v(2) = .01
v(3) = .01
n = 3
nv = 2
d = 10
mx = 300
j = 1
fs = 0
GOSUB 5000
b = f
cb = cf
fs = fz
wi = si
wn = sn
wm = sm
CLS 0
PRINT " Delta initial ="; b
IF b < rr GOTO 4640
FOR a = 1 TO nv
PRINT " Pas ="; a; " Calcul en cours"
c = 0
4230 FOR k = n TO 1 STEP -1
s = 1
FOR i = 1 TO n
IF i <> k GOTO 4430
4270 x(i) = x(i) + s * v(i)
ip = i + n
IF x(i) < x(ip) GOTO 4410
ip = i + 2 * n
IF x(i) > x(ip) GOTO 4400
GOSUB 5000
PRINT " Delta ="; f
j = j + 1
IF j > mx GOTO 4630
IF f <= b GOTO 4370
IF s = -2 GOTO 4410
4400 s = -2
GOTO 4270
4370 b = f
cb = cf
fs = fz
wi = si
wn = sn
wm = sm
IF b < rr GOTO 4640
GOTO 4430
4410 s = -1
x(i) = x(i) - s * v(i)
c = c + 1
4430 NEXT i
NEXT k
IF c >= n THEN GOTO 4580
c = 0
GOTO 4230
4580 FOR i = 1 TO n
v(i) = v(i) / d
NEXT i
NEXT a
GOTO 4640
4630 IF lim = 0 THEN GOTO 4635
PRINT "Arrt aprs"; mx; " essais"
GOTO 4640
4635 LPRINT "Arrt aprs"; mx; " essais"
4640 IF lim = 0 THEN GOTO 4645
x[3] = .1;
x[4] = .1;
x[5] = -2;
x[6] = 9;
x[7] = 7;
x[8] = 2;
v[0] = v[1] = v[2] = .01;
int n = 3;
int nv = 2;
int d = 10;
int mx = 300;
int j = 1;
double fs = 0;
Integration(indiumCd, nickelCd, magnésium);
b = f;
double cb = cf;
fs = fz;
double wi = si;
double wn = sn;
double wm = sm;
int ip = 0; int a 0, kk 0, i = 0;
double c = 0;
if (b >= rr) {
for (a = 1; a < nv+1; a++) {
for (kk = n-1; kk > -1; kk--) {
int s = 1;
for (i = 0; i < n; i++) {
if (i == kk) {
x[i] += s * v[i];
ip = i + n;
while (x[i] >= x[ip]) {
ip = i + 2 * n;
if (x[i] <= x[ip]) {
Integration(indiumCd, nickelCd, magnésium);
j++;
if (j > mx) { break; } else {
if (f <= b) {
b = f;
cb = cf;
fs = fz;
wi = si;
wn = sn;
wm = sm;
break;
} else {
if (s == -2) {
s = -1;
x[i] -= s * v[i];
c++;
break;
} else {
s = -2;
x[i] += s * v[i];
ip = i + n;
}
}
}
} else {
s = -2;
x[i] += s * v[i];
ip = i + n;
}
}//while
if (x[i] < x[ip]) {
s = -1;
x[i] -= s * v[i];
c++;
}
if (b < rr) { break; }
if (j > mx) { break; }
}
}//i
if (c >= n) { break; } else {
c = 0;
kk = n;
}
if (b < rr) { break; }
if (j > mx) { break; }
}//k
if (b < rr) { break; }
if (j > mx) { break; }
for (i = 0; i < n; i++) { v[i] /= d; }
}//a
}//4640
GOSUB 5000 correspond a une fonction Integration().
Voili voilou !!
cs_GodConan
Messages postés2113Date d'inscriptionsamedi 8 novembre 2003StatutContributeurDernière intervention 6 octobre 201212 19 août 2005 à 18:14
ben je l ai regarder il est vraiment crade cette algo ... respecte aucune structure ... et ca c est grave de plus il manque plusieurs donne pour le traduire proprement :-(
enfin voila ce que j en ai fait ... ( pas tester biensur c est fait a l arrache . .;o) )
private void tonAlgo( double alpha, double beta, double gamma )
{
double[] x = new double[ 10 ]; // on utilise pas le 0 mais c pour simplifier la traduction
double[] v = new double[ 4 ];
// 4150
x[ 1 ] = alpha;
x[ 2 ] = beta;
x[ 3 ] = gamma;
x[ 4 ] = .1;
x[ 5 ] = .1;
x[ 6 ] = -2;
x[ 7 ] = 9;
x[ 8 ] = 7;
x[ 9 ] = 2;
v[ 1 ] = .01;
v[ 2 ] = .01;
v[ 3 ] = .01;
int n = 3;
int nv = 2;
int d = 10;
int mx = 300;
int j = 1;
double fs = 0;
//execute la fonction 5000
// integration bidule
double b = f;
double cb = cf;
fs = fz;
double wi = si;
double wn = sn;
double wm = sm;
System.out.println( " Delta initial =" + b );
if( b >= rr ) // goto 4640
{
for( int a = 1; a <= nv; a++ ) // FOR a = 1 TO nv
{
System.out.println( " Pas =" + a + " Calcul en cours" );
while ( true )
{
int c = 0;
// 4230
for( int k = n; k<= 1; k-- ) //FOR k = n TO 1 STEP -1
{
int s = 1;
for( int i = 1; i <= n; i++ ) //FOR i = 1 TO n
{
if( i != k ) continue; // IF i <> k GOTO 4430
// 4270
x[i] = x[i] + s * v[i];
int ip = i + n;
if ( x[i] < x[ip] ) // IF x(i) < x(ip) GOTO 4410
{
s = -1;
x[i] = x[i] - s * v[i];
c = c + 1;
continue i;
}
ip = i + 2 * n;
while ( x[i] > x[ip] ) // IF x(i) > x(ip) GOTO 4400
{
s = -2;
x[i] = x[i] + s * v[i];
ip = i + n;
if ( x[i] < x[ip] ) // IF x(i) < x(ip) GOTO 4410
{
s = -1;
x[i] = x[i] - s * v[i];
c = c + 1;
continue i;
}
}
//execute la fonction 5000
// integration bidule
System.out.println( " Delta =" + f );
j = j + 1;
if ( j > mx ) // IF j > mx GOTO 4630
{
System.out.println( "Arrt aprs"+ mx+ " essais" );
return;
}
if ( f <= b ) //IF f <= b GOTO 4370
{
b = f;
cb = cf;
fs = fz;
wi = si;
wn = sn;
wm = sm;
if( b < rr ) // IF b < rr GOTO 4640
{
return; // apriorie il ce passe rien
}
continue; //GOTO 4430
} if ( s -2 ) //IF s -2 GOTO 4410
{
s = -1;
x[i] = x[i] - s * v[i];
c = c + 1;
}
} //NEXT i
} // NEXT k
if ( c >= n ) // IF c >= n THEN GOTO 4580
break; // kitte le while
} //GOTO 4230
for( int i = 1; i <= n; i++ )
{
v[i] = v[i] / d;
}
} // while
} // NEXT a
}
en fait le passage delicas ce trouve ici
4270 x(i) = x(i) + s * v(i)
ip = i + n
IF x(i) < x(ip) GOTO 4410
ip = i + 2 * n
IF x(i) > x(ip) GOTO 4400
GOSUB 5000
PRINT " Delta ="; f
j = j + 1
IF j > mx GOTO 4630
IF f <= b GOTO 4370
IF s = -2 GOTO 4410
4400 s = -2
GOTO 4270
g resolu le prob en recopiant un morceau de code .... ( methode a faire )
de plus
4400
4370
4410
ces 3 label ne sont pas consecutif es ce une erreur ??!!!
Enderounet
Messages postés29Date d'inscriptionmardi 2 août 2005StatutMembreDernière intervention30 août 2005 19 août 2005 à 15:52
c les conditions de sortie de boucles sur le java qui sont pas bonnes a priori.
saleté de GOTO c horrible. ca fait 2 jours que je suis dessus et tjs pas trouvé la soluce ...