

figure(1)
f=@(x,y) 25+15*(x+0.5).^4+20*(y-0.5).^4;
f1=@(x,y) 60*(x+0.5).^3;
f2=@(x,y) 80*(y-0.5).^3;
g=@(x,y) f(0,0)+f1(0,0).*x+f2(0,0).*y;
[x1,y1]=meshgrid(0:0.05:0.6,-0.6:0.05:0);
z1=f(x1,y1);
surf(x1,y1,z1)
set(0,'defaulttextinterpreter','latex')
zlabel('$z$');

%te=text(0,0,4.5,['\hspace*{-2  cm}$ D_vf(a,b)= $ '%num2str(-cos(t(n))/2+sin(t(n))/2)],'FontSize',14 ,'Interpreter','latex');
 set(gca,'XTickLabel',{'a',' ',' ',' x',''})
  set(gca,'YTickLabel',{'','y ',' ',' ','b'}) 
   set(gca,'ZTickLabel',{'0','',' ',' ',''}) 
hold on
[x,y]=meshgrid([0 0.6],[-0.6 0]);
surf(x,y,zeros(size(x)),55*ones(size(x))) %xy-planet
axis([-0.05 0.8 -0.8 0.05 0 80])
alpha(0.9)
shading interp
rotate3D on
grid off
z=g(x,y);
surf(x,y,z,70*ones(size(x))) % tangentplanet
surf(x,y,f(0,0)*ones(size(x)),57*ones(size(x))) % planet z=f(a,b)
plot3([0 0 0.6 0.6 0],[0 -0.6 -0.6 0 0],[0 0 0 0 0])
z=0:2:f(0,0);
x=zeros(size(z));
y=zeros(size(z));
plot3(x,y,z,':','Linewidth',1.5)
z=0:2:f(0,0);
x=zeros(size(z));
y=-0.6*ones(size(z));
plot3(x,y,z,':','Linewidth',1.5)
z=g(0,-0.6):2:f(0,-0.6);
x=zeros(size(z));
y=-0.6*ones(size(z));
plot3(x,y,z,':','Linewidth',1.5)
plot3([0 0],[-0.6 -0.6],[f(0,0),g(0,-0.6)],'Linewidth',1.5)
z=0:2:f(0,0);
x=0.6*ones(size(z));
y=zeros(size(z));
plot3(x,y,z,':')
z=g(0.6,0):2:f(0.6,0);
x=0.6*ones(size(z));
y=zeros(size(z));
plot3(x,y,z,':','Linewidth',1.5)
plot3([0.6 0.6],[0 0],[f(0,0),g(0.6,0)],'Linewidth',1.5)
z=0:2:f(0,0);
x=0.6*ones(size(z));
y=-0.6*ones(size(z));
plot3(x,y,z,':','Linewidth',1.5)
z=g(0.6,-0.6):2:f(0.6,-0.6);
x=0.6*ones(size(z));
y=-0.6*ones(size(z));
plot3(x,y,z,':','Linewidth',1.5)
plot3([0.6 0.6],[-0.6 -0.6],[f(0,0),g(0.6,-0.6)],'Linewidth',1.5)
x=0:0.05:0.6;
y=zeros(size(x));
plot3(x,y,f(x,y))
x=0:0.05:0.6;
y=-0.6*ones(size(x));
plot3(x,y,f(x,y))
y=-0.6:0.05:0;
x=0.6*ones(size(x));
plot3(x,y,f(x,y))
y=-0.6:0.05:0;
x=zeros(size(x));
plot3(x,y,f(x,y))
text(0,0,3,'$(a,b,0)$')
text(0,0,f(0,0)+10,'$(a,b,f(a,b))$')
text(0,-0.6,3,'$(a,y)$')
text(0,-0.62,(g(0,0)+g(0,-0.6))/2-0.5,'$f_2(a,b)(y-b)$')
text(0.6,0,3,'$(x,b)$')
text(0.62,0,(g(0,0)+g(0.6,0))/2-0.5,'$f_1(a,b)(x-a)$')
text(0.6,-0.6,3,'$(x,y)$')
text(0.62,-0.62,(g(0,0)+g(0.6,-0.6))/2,'$f_1(a,b)(x-a)+ \\ f_2(a,b)(y-b)$')
text(0.4,-0.4,g(0.4,-0.4)+3,'tangentplanet')
text(0.5,-0.5,f(0.5,-0.5)-2,'$z=f(x,y)$')
hold off, pause

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

figure(2)

[x,y]=meshgrid([0 0.6],[-0.6 0]);

cm = colormap;
Q = ones([size(x) 3])

z=g(x,y)-f(0,0);
n=56;
F=Q;for i=1:3,F(:,:,i)=cm(n,i)*Q(:,:,i);end,
surf(x,y,z,F)
zlabel('$z$');
axis([-0.05 0.8 -0.8 0.05 -20 20])
alpha(0.8)
shading interp
rotate3D on
grid off
 set(gca,'XTickLabel',{'0',' ',' ',' h',''})
  set(gca,'YTickLabel',{'','k ',' ',' ','0'}) 
   set(gca,'ZTickLabel',{'','','0 ',' ',''}) 

hold on
n=40;
F=Q;for i=1:3,F(:,:,i)=cm(n,i)*Q(:,:,i);end,
surf(x,y,zeros(size(x)),F) % planet z=f(a,b)
alpha(0.8)
%plot3([0 0 0.6 0.6 0],[0 -0.6 -0.6 0 0],[0 0 0 0 0])
z=0:2:f(0,0);
x=zeros(size(z));
y=zeros(size(z));

z=0:2:f(0,0);
x=zeros(size(z));
y=-0.6*ones(size(z));

z=g(0,-0.6):2:f(0,-0.6);
x=zeros(size(z));
y=-0.6*ones(size(z));

plot3([0 0],[-0.6 -0.6],[0,g(0,-0.6)-f(0,0)],'Linewidth',1.5)


z=g(0.6,0):2:f(0.6,0);
x=0.6*ones(size(z));
y=zeros(size(z));

plot3([0.6 0.6],[0 0],[0,g(0.6,0)-f(0,0)],'Linewidth',1.5)

z=g(0.6,-0.6):2:f(0.6,-0.6);
x=0.6*ones(size(z));
y=-0.6*ones(size(z));

plot3([0.6 0.6],[-0.6 -0.6],[0,g(0.6,-0.6)-f(0,0)],'Linewidth',1.5)


text(0,0,-1,'$(0,0,0)$')

text(0,-0.6,-1,'$(0,k,0)$')
text(0,-0.62,(g(0,0)+g(0,-0.6))/2-0.5-f(0,0),'$f_2(a,b)k$')
text(0.6,0,-1,'$(h,0,0)$')
text(0.62,0,(g(0,0)+g(0.6,0))/2-0.5-f(0,0),'$f_1(a,b)h)$')
text(0.6,-0.6,-1,'$(h,k,0)$')
text(0.62,-0.62,(g(0,0)+g(0.6,-0.6))/2-f(0,0),'$df = f_1(a,b)h+  f_2(a,b)k$')
text(0.3,-0.5,g(0.4,-0.4)+6-f(0,0),'graf till differentialen i punkten $(a,b)$')
hold off
