clf
f=@(x,y) 1+(50-15*(x+0.5).^2-20*(y-0.5).^2)/80;
f1=@(x,y) -30*(x+0.5)/80;
f2=@(x,y) -40*(y-0.5)/80;
g=@(x,y) f(0,0)+f1(0,0).*x+f2(0,0).*y;
[x,y]=meshgrid([-1 1],[-1 1]);
z=g(x,y);
surf(x,y,z,-10*ones(size(x)))
hold on
alpha(0.2)
[x,y]=meshgrid(-1:0.1:1,-1:0.1:1);
z=f(x,y);
surf(x,y,z)
axis equal
axis([-1 1 -1 1 0 2])
cy1=quiver(0,0,1,0,0,'Color','b','LineWidth',1.5);
cy0=quiver3(0,0,f(0,0),1,0,f1(0,0),0,'Color','r','LineWidth',1.5 );
cy2=plot3([0 1],[0 0],[f(0,0) f(0,0)],'black','LineWidth',1 );
cy3=plot3([1 1],[0 0],[f(0,0) f(0,0)+f1(0,0)],'black','LineWidth',1 );
v=text(1.1,0,0,'$\bf{i}$','FontSize',12,'Interpreter','latex');    
te1=text(1.5,0,2,['\hspace*{-2  cm}$ f_1(a,b)= $ ' num2str(f1(0,0))],'FontSize',14,'Interpreter','latex');
an1=quiver3(1.5,0,1.9,1-1.5,0-0,(f(0,0)+f(0,0)+f1(0,0))/2-1.9, 0,'Color','black');

cy1=quiver(0,0,0,1,0,'Color','b','LineWidth',1.5);
cy0=quiver3(0,0,f(0,0),0,1,f2(0,0),0,'Color','r','LineWidth',1.5 );
cy2=plot3([0 0],[0 1],[f(0,0) f(0,0)],'black','LineWidth',1 );
cy3=plot3([0 0],[1 1],[f(0,0) f(0,0)+f2(0,0)],'black','LineWidth',1 );
v=text(0,1.1,0,'$\bf{j}$','FontSize',12,'Interpreter','latex');    
te=text(0,1.5,2,['\hspace*{-2  cm}$ f_2(a,b)= $ ' num2str(f2(0,0))],'FontSize',14,'Interpreter','latex');
an=quiver3(0,1.5,1.9,0-0,1-1.5,(f(0,0)+f(0,0)+f2(0,0))/2-1.9, 0,'Color','black');

v=text(-0.2,-0.2,0,'$(a,b)$','FontSize',12,'Interpreter','latex');   % shading interp
title('Illustration av partiell derivata, tangentplan och normal','FontSize',14 ,'Interpreter','latex')
rotate3D on
figure(1)
pause
delete(te)
delete(an)
delete(te1)
delete(an1)
v2=text(0,1.1,f(0,0)+f2(0,0)+0.1,'$\bf{j}+f_2(a,b)\bf{k}$','FontSize',12,'Interpreter','latex');   
v3=text(1.1,0,f(0,0)+f1(0,0),'$\bf{i}+f_1(a,b)\bf{k}$','FontSize',12,'Interpreter','latex');
figure(1)
pause
t=-1:1;
plot3(0+f1(0,0)*t,0+f2(0,0)*t,f(0,0)-t,'Color','r','LineWidth',1.5 );
figure(1)