% exempel som illustrerar en funktion som har gränsvärde i (0,0), 
% men ej är definierad i (0,0). 
clf
set(0,'defaulttextinterpreter','latex')
f=@(x,y) 2+x.*y.^2./(x.^4+y.^2);
x=linspace(-2,3,101);y=linspace(-2,3,100);
[X Y] = meshgrid(x,y);
Z=f(X,Y);
surf(X,Y,Z);
shading interp
title('$\displaystyle{f(x,y)=2+\frac{xy^2}{x^4+y^2}}$','FontSize',14,'Interpreter','latex') 
grid on
hold on
plot3(0,0,0,'.')
pause
plot3(0,0,0,'*')
text(0,-0.3,0.1,'(0,0)')
rotate3D on 
pause
nivaer=linspace(2-0.5,2+0.5,10);
contour(X,Y,Z,nivaer)
pause
t=-1:0.05:1;
x=@(t) 1-t;
y=@(t) (1-t)/2;
for n=1:length(t)-1
    plot3([x(t(n)) x(t(n+1))], [y(t(n)) y(t(n+1))], [f(x(t(n)),y(t(n))) f(x(t(n+1)),y(t(n+1)))]) 
    plot3([x(t(n)) x(t(n+1))], [y(t(n)) y(t(n+1))], [0 0]) 
    pause(0.1) 
end
pause
t=-2:0.05:0;
x=@(t) -t.^2/2;
y=@(t) t;
for n=1:length(t)-1
    plot3([x(t(n)) x(t(n+1))], [y(t(n)) y(t(n+1))], [f(x(t(n)),y(t(n))) f(x(t(n+1)),y(t(n+1)))]) 
    plot3([x(t(n)) x(t(n+1))], [y(t(n)) y(t(n+1))], [0 0]) 
    pause(0.1) 
end
pause
t=5*pi/8:0.05:5*pi/4;
x=@(t) 1+sqrt(2)*cos(t);
y=@(t) 1+sqrt(2)*sin(t);
for n=1:length(t)-1
    plot3([x(t(n)) x(t(n+1))], [y(t(n)) y(t(n+1))], [f(x(t(n)),y(t(n))) f(x(t(n+1)),y(t(n+1)))]) 
    plot3([x(t(n)) x(t(n+1))], [y(t(n)) y(t(n+1))], [0 0]) 
    pause(0.1) 
end
pause
text(0.6,0.4 ,3,'$f(x,y)$ är ej def i (0,0) men','FontSize',14,'Interpreter','latex');
text(0.6,0.4 ,3,'$f(x,y) \rightarrow 2$ då $(x,y)\rightarrow (0,0)$ ','FontSize',14,'Interpreter','latex');
%text(0.6,0.4 ,2.9,'lim_{(x,y)\rightarrow (0,0)}f(x,y)=2','FontSize',14);
hold off

