Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc
- clear all
- %funkcja
- f = @(x,y) 2.*x.^2 + y.^2 + x.*y - 6.*x - 5.*y +8;
- %alfa
- L=0.1;
- %punkty poczatkowe
- x=-4;
- y=-4;
- %linie
- xl=linspace(-5,5,100);
- yl=linspace(-5,5,100);
- %siatka
- [X,Y]=meshgrid(xl,yl);
- Z=f(X,Y);
- %wykres konturowy
- contour(X,Y,Z,20)
- minf=0;
- tab=zeros(1,5);
- i=0;
- while (1)
- i=i+1;
- tab(1,1)=f(x+L,y);
- tab(1,2)=f(x-L,y);
- tab(1,3)=f(x,y+L);
- tab(1,4)=f(x,y-L);
- tab(1,5)=f(x,y);
- z=min(tab);
- if(f(x+L,y) == z )
- line([x,x+L],[y,y])
- x=x+L;
- elseif (f(x-L,y) == z )
- line([x,x-L],[y,y])
- x=x-L;
- elseif (f(x,y+L) == z )
- line([x,x],[y,y+L])
- y=y+L;
- elseif(f(x,y-L) == z )
- line([x,x],[y,y-L])
- y=y-L;
- else
- x
- y
- minf=f(x,y)
- i
- break;
- end
- end
- title(sprintf('Minimum w f(%0.0f,%0.0f) = %f',x,y,minf));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement