function M=methodegradient();

deff('z=f(x,y)','z=x.^4-x.^3+2*x.*y+y.^2-2*y+1');
//deff('z=f(x,y)','z=x.^2-x+y.^2-3*y+2');
M=[5;5];
n=2000;
delta=10^(-5);
pas=10^(-2);

for i=1:n
	dM=1/delta*[f(M(1)+delta,M(2))-f(M(1),M(2));f(M(1),M(2)+delta)-f(M(1),M(2))];
	M=M-pas*dM;
end;

fmin=f(M(1),M(2));
xset('window',1);
xbasc();
fplot3d(-5:0.2:5,-10:0.5:10,f);
plot3d([-5;5],[-10;10],fmin*ones(2,2));
xset('window',2);
xbasc();
fgrayplot(-2:0.1:1,-5:0.1:5,f);

endfunction;

//----------------------------------------------------

function chaleur()

n=30;
iter=200;

A=zeros(n,n);
A(:,1)=3*ones(n,1);A(:,n)=ones(n,1);
A(n/2,n/2)=10; //ajout d'une source ponctuelle


for t=1:iter
	for i=2:n-1
		for j=2:n-1
			A(i,j)=1/4*(A(i-1,j)+A(i+1,j)+A(i,j-1)+A(i,j+1));
		  if and([i,j]==[n/2,n/2]) then A(i,j)=10; end; //ajout d'une source ponctuelle
		end;
	end;
end;

xbasc();
plot3d(1:n,1:n,10*A);

endfunction;
