mashlukashova

Untitled

May 19th, 2021
964
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. clear all;
  2. close all;
  3. clc
  4. [Xplot,Yplot] = meshgrid(-8:0.5:8,-8:0.5:8);
  5. Zplot = myFunction(Xplot,Yplot);
  6. surf(Xplot,Yplot,Zplot);
  7.  
  8.  
  9.  
  10. N = 10000;
  11. M = 2;
  12. Ksi = rand(M,N);
  13. A = [-8 -8];
  14. B = [8 8];
  15. for k=1:M
  16.     for i=1:N
  17.         Ke(k,i) = A(k) + (B(k)-A(k)).*Ksi(k,i);
  18.     end
  19. end
  20. Ze = myFunction(Ke(1,:),Ke(2,:));
  21. Min = min(Ze)
  22.  
  23. for i=1:N
  24.     if(Min == Ze(i))
  25.     Ke(:,i)
  26.     end
  27. end
  28.  
  29.  
  30. T = 50;
  31. T0 = 0.0001;
  32. Nu = 0.99;
  33. X0 = [0 0];
  34. X=X0;
  35. l=0;
  36. while (T>T0)
  37.     l = l + 1;
  38.     z = randn(2,1);
  39.     Ks = rand(2,1);
  40.    
  41.     flag = 0;
  42.     for k=1:M
  43.         Xnew(k) = X(k) + z(k)*T;
  44.         %*((1+l/T)^(2*Ks(k)-1)-1);
  45.         if ((A(k) > Xnew(k))||(B(k) < Xnew(k)))
  46.             flag = 1;
  47.         end
  48.     end
  49.     if (flag == 1)
  50.         continue;
  51.     end
  52.     Z = myFunction(X(:,1),X(:,2));
  53.     Znew = myFunction(Xnew(:,1),Xnew(:,2));
  54.     DeltaE = Znew - Z;
  55.     if (DeltaE<0)
  56.         X=Xnew;
  57.     else
  58.         P = exp(-DeltaE/T);
  59.         if (rand()<P)
  60.             X = Xnew;
  61.         else
  62.             T=Nu*T;
  63.         end
  64.     end  
  65. end
  66. X
  67. myFunction(X(1),X(2))
  68.  
  69.  
  70.  
  71. %%%%%%%%%%%%%%%% функция другой файл
  72. function result = myFunction(x,y)
  73. result = (x.^2+y.^2)/2 - 12*(cos(x)+cos(y));
  74. end
RAW Paste Data