f=inline('y.*exp(-x.*x-y.*y)'); x=-2:0.1:2; y=-1:0.1:2; [X,Y]=meshgrid(x,y); Z=f(X,Y); h1=figure; set(h1,'Color','w') mesh(X,Y,Z) surf(X,Y,Z) mesh(X,Y,Z) contour(X,Y,Z) meshc(X,Y,Z) subplot(2,2,1),mesh(X,Y,Z),title('mesh') subplot(2,2,2),meshc(X,Y,Z),title('meshc') subplot(2,2,3),surf(X,Y,Z),title('surf') subplot(2,2,4),contour(X,Y,Z),title('contour')
h2=figure; subplot(1,2,1); set(h2,'Color','w') [x,y,z]=sphere(10); surf(x,y,z) title('Sphere low resolution') % Drawing sphere with a higher resolution subplot(1,2,2) [x,y,z]=sphere(40); surf(x,y,z) title('Sphere higher resolution')
h3=figure; subplot(1,4,1); set(h3,'Color','w') [x,y,z]=cylinder(40); surf(x,y,z) title('Cylinder') % Drawing two baloons (special case of the cylinder) t=0:0.1:2*pi; r=sin(t); [x,y,z]=cylinder(r); subplot(1,4,2) surf(x,y,z) title('Two baloons') % Drawing a cone (special case of the cylinder) subplot(1,4,3) cylinder([3 0]) title('Cone')
subplot(1,4,4)
x=0:0.1:2*pi;
r=sin(x)+2;
cylinder(r)
title('Flower vasa')
Define the vertices
h4=figure; set(h4,'Color','w') v=[ 1 1 0; 1 2 0; 1.5 1.5 1; 2 2 0; 2 1 0]; % Define the faces f=[ 1 2 3; 2 4 3; 4 5 3; 1 5 3]; % Draw faces patch('vertices',v,'faces',f,'facecolor','g') axis([0 3 0 3 0 1]) grid on
h5=figure; set(h5,'Color','w'); set(h5,'Name','Throwing'); Alpha=30; % Expressed in grade v=10; % [m/s] Release velocity h=5; % [m] Height of release % Transform ange in radian AlphaRad=Alpha*pi/180; % Horizontal release velocity vx=v*cos(AlphaRad); % Vertical release velocity vy0=v*sin(AlphaRad); % Vertical position y=h; % Horizontal position x=0; % Time t=0; % Time step dt=0.01; % [sec] % Distance thrown xmax=vx*(vy0+sqrt(vy0^2 + 19.6*h))/9.8; ymax=h+vy0^2/19.6; while y>=0 plot(x,y,'-ok'); axis([0 xmax*1.1 0 ymax*1.1]) pause(dt); t=t+dt; x=vx*t; y=h+vy0*t-4.9*t^2; end