Advertisement
Guest User

guwno123PL69

a guest
Mar 22nd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. clc
  2. clear all
  3. %funkcja
  4. f = @(x,y) 2.*x.^2 + y.^2 + x.*y - 6.*x - 5.*y +8;
  5.  
  6. %alfa
  7. L=0.1;
  8. %punkty poczatkowe
  9. x=-4;
  10. y=-4;
  11. %linie
  12. xl=linspace(-5,5,100);
  13. yl=linspace(-5,5,100);
  14. %siatka
  15. [X,Y]=meshgrid(xl,yl);
  16. Z=f(X,Y);
  17. %wykres konturowy
  18. contour(X,Y,Z,20)
  19. minf=0;
  20. tab=zeros(1,5);
  21. i=0;
  22. while (1)
  23.  
  24. i=i+1;
  25. tab(1,1)=f(x+L,y);
  26. tab(1,2)=f(x-L,y);
  27. tab(1,3)=f(x,y+L);
  28. tab(1,4)=f(x,y-L);
  29. tab(1,5)=f(x,y);
  30. z=min(tab);
  31.  
  32. if(f(x+L,y) == z )
  33. line([x,x+L],[y,y])
  34. x=x+L;
  35.  
  36. elseif (f(x-L,y) == z )
  37. line([x,x-L],[y,y])
  38. x=x-L;
  39.  
  40. elseif (f(x,y+L) == z )
  41. line([x,x],[y,y+L])
  42. y=y+L;
  43.  
  44. elseif(f(x,y-L) == z )
  45. line([x,x],[y,y-L])
  46. y=y-L;
  47.  
  48. else
  49. x
  50. y
  51. minf=f(x,y)
  52. i
  53. break;
  54. end
  55. end
  56. title(sprintf('Minimum w f(%0.0f,%0.0f) = %f',x,y,minf));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement