clearvars
close all

zmin=-3.2;
zmax=1.1;
r=sqrt(1-zmin);

t=linspace(0,2,2000);
x1=t;
y1=sqrt(4*t-2*t.^2);
z1=t.^2-4*t+1;

plot3(x1,y1,z1,'-k','lineWidth',3)

view(52,46)

xlabel('X')
ylabel('Y')
zlabel('Z')

text=['Intersection between the surfaces $z=x^2-4x+1$',...
    ' and $1-z=x^2+y^2$'];

title(text,'interpreter','LaTeX')

%text(r,r,r/2,'z=x^2-4x+1')
axis equal
axis([-r,r,-r,r,zmin,zmax]) 
hold on
plot3(x1,-y1,z1,'-k','lineWidth',3)
[x,y]=meshgrid(-2.1:0.05:2.3);
z=x.^2-4*x+1;
mesh(x,y,z)
tt=x.^2+y.^2;
zz=1-tt;
mesh(x,y,zz)
z1=zmin*ones(1,size(t,2));
plot3(x1,y1,z1,'-b','lineWidth',2)
plot3(x1,-y1,z1,'-b','lineWidth',2)

hold off
