% 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) 30+x.*y.^2./(x+y.^2);
y=linspace(-3,3,251);
%y=linspace(-2,1,100)
x=linspace(-2,0.53,251);
%y=linspace(-2,1,100);
[X Y] = meshgrid(x,y);
X=X.*(abs(X+Y.^2)>0.03.*(X.^2+Y.^2));
X(find(X==0))=NaN;
Z=f(X,Y);
surf(X,Y,Z);
shading interp
view([-2 -0.7 1.2])
title('$\displaystyle{f(x,y)=30+\frac{xy^2}{x+y^2}}$','FontSize',14,'Interpreter','latex') 
grid on
hold on
plot3(0,0,0,'.')
pause
plot3(-(1.25)^2,1.25,0,'*')
text(-(1.25)^2-0.2,0.95,0.1,'(-b^2,b)')
rotate3D on 
pause
contour(X,Y,Z)
pause
t=-1.35:0.03:-0.06;
x=@(t) -(1.25)^2;
y=@(t) 1.25-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=-1:0.03:-0.06;
x=@(t) -(1.25)^2+t.^2/2;
y=@(t) 1.25+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=-0.3:0.02:-0.02;
x=@(t) 0;
y=@(t) 5*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=-0.8:0.03:-0.04;
x=@(t) -t.^2+t.^5;
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
text(-1,2 ,72,'$f(x,y)$ är ej def längs kurvan $x=-y^2$ och','FontSize',14,'Interpreter','latex');
text(-1,2 ,65,'$f(x,y)$ saknar gränsvärde då $(x,y)\rightarrow (-b^2,b)$','FontSize',14,'Interpreter','latex');
text(-1,2 ,58,'Gränsvärde saknas också då $(x,y)\rightarrow (0,0)$','FontSize',14,'Interpreter','latex');
hold off

