% 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.^2.*y./(x.^4+y.^2);
x=linspace(-2,3,151);y=linspace(-2,3,150);
[X Y] = meshgrid(x,y);
Z=f(X,Y);
surf(X,Y,Z);
shading interp
title('$\displaystyle{f(x,y)=2+\frac{x^2y}{x^4+y^2}}$','FontSize',14,'Interpreter','latex') 
grid on
hold on
plot3(0,0,0,'.')
pause
plot3(0,0,0,'*')
text(-0.2,0.4,0.1,'(0,0)')
rotate3D on 
pause
nivaer=linspace(2-0.5,2+0.5,10);
contour(X,Y,Z,nivaer)
pause
t=-1.6:0.03:0;
x=@(t) -t;
y=@(t) t.^3/2+t.^4/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.04: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=-1:0.02:1;
x=@(t) t-1;
y=@(t) (1-t)/4;
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.5:0.03:0;
x=@(t) -t;
y=@(t) 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
text(-4,-1 ,1.6,'$f(x,y)$ är ej def i $(0,0)$ och','FontSize',14,'Interpreter','latex');
text(-4,-1 ,1.3,'$f(x,y)$ saknar gränsvärde då $(x,y) \rightarrow (0,0)$','FontSize',14,'Interpreter','latex');
hold off

