function []=code5;
% Draw a surface over a specified boundary
% Draw z=9-x^2 over the triangle y=0,y=x,x=3 in Oct.I.
% This routine uses Delaunay triangles to creat a triangular mesh.

% First build a rectangular mesh that encloses the triangle, or whatever
% boundary you may have.
minx=0; maxx=3; dx=0.05;
miny=0; maxy=3; dy=0.05;
[x,y]=meshgrid(minx:dx:maxx,miny:dy:maxy);

% Find all the points from the above mesh that are inside the triangle.
k=find(y<=x);
x1=x(k); y1=y(k);
% Evaluate the surface function only at points inside the triangle
z1=9-x1.^2;   % change this to draw other surfaces


 tri = delaunay(x1,y1);
       trisurf(tri,x1,y1,z1);
 colorbar 'v';
 shading interp;
 hold on;
%=======================================
% project the boundary onto the xy plane.
% Zoom into the boundary to see the triangular mesh
trisurf(tri,x1,y1,0*z1);
%shading interp;
view(120,20);

% Draw a set of axes
xmax=max(max(x1)); ymax=max(max(y1)); zmax=max(max(z1));  
line([0,xmax],[0,0],[0,0],'LineWidth',2,'Color','r');
line([0,0],[0,ymax],[0,0],'LineWidth',2,'Color','r');
line([0,0],[0,0],[0,zmax],'LineWidth',2,'Color','r');
text(xmax+0.1,0,0,'X','Color','r','FontSize',15);
text(0,ymax+0.1,0,'Y','Color','r','FontSize',15);
text(0,0,zmax+0.01,'Z','Color','r','FontSize',15);
xlabel('x'); ylabel('y'); zlabel('z');
title('Surface');

% ****************************************************************
% ****************************************************************
%  Here is some code for drawing over a circular region. Copy and paste
%  this into a new m-file, uncomment the lines that have only 1 % sign.
% ****************************************************************

%function []=mycodename;
% % Draw z=x^2-y^2+1 over the circle  x^2+y^2 = 1 .

%minx=0; maxx=3; dx=0.05;
%miny=0; maxy=3; dy=0.05;
%[x,y]=meshgrid(minx:dx:maxx,miny:dy:maxy);

% % Find all the points from the above mesh that are inside the triangle.
%k=find((1-x.^2-y.^2)>=0);

%x1=x(k); y1=y(k);
%z1=x1.^2-y1.^2+1;

% tri = delaunay(x1,y1);
%       trisurf(tri,x1,y1,z1);
% colorbar 'v';
% shading interp;

% %=======================================
