Bonjour,
J'ai écrit un tout petit bout de code (matlab), très simple dans sa structure. Il répond exactement à mon problème, ..., sauf qu'il est trop lent, beaucoup trop lent (je dois faire tourner le code avec une valeur bien supérieure à 99)!
Y-a-t'il moyen de réduire la durée, par exemple sur les lignes de tests (je suis malheureusement tributaire de mon ordi, un portable dell M1330!!!)?
Code matlab : 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 % N=99 --> < 10 s clc; N=99; n=0; for a=1:N for b=1:N for c=1:N for d=1:N if a+b+c+d > N break end alpha=(a*d-b*c)^0.5; if a*d-b*c<=0 || alpha-round(alpha)~=0 continue else beta1=(a+d+2*alpha)^0.5; beta2=(a+d-2*alpha)^0.5; if beta1-round(beta1)~=0||beta2-round(beta2)~=0 continue else A1=(beta1^2+a-d)/(2*beta1); A2=(beta2^2+a-d)/(2*beta2); B1=b/beta1; B2=b/beta2; C1=c/beta1; C2=c/beta2; D1=(beta1^2-a+d)/(2*beta1); D2=(beta2^2-a+d)/(2*beta2); if round(A1)==A1 && A1>0 && round(A2)==A2 && A2>0 && round(B1)==B1 && B1>0 && round(B2)==B2 && B2>0 && round(C1)==C1 && C1>0 && round(C2)==C2 && C2>0 && round(D1)==D1 && D1>0 && round(D2)==D2 && D2>0 n=n+1; else end end end end end end end n
Merci d'avance.
Partager