%This script demonstrates plotting in 3D
%P. Chidyagwai
% 01/24/2019
%MA 302
clc
clf
%%Space curves
t =linspace(0,10*pi,1000);
x= t.*cos(t);
y= t;
z = t.*sin(t);
plot3(x,y,z,'LineWidth',2);
xlabel('x'),ylabel('y'),zlabel('z')
title('Space curve');
grid on
print -djpeg 3Dplot1.jpg;

clf
%%illustration of 2D domain
x=1:4
y=2:6
[X,Y]=meshgrid(x,y)
plot(X,Y,'r*')
print -djpeg 3Dplot2.jpg;
clf

Z =X+Y;
mesh(X,Y,Z);
title('z=x+y');
xlabel('x') 
ylabel('y') 
zlabel('z')
print -djpeg 3Dplot3.jpg;
%%
%%Another example
%create a square grid
clf

[X,Y]=meshgrid(linspace(-10,10,50));
Z = sin(X)-sin(Y);
surf(X,Y,Z);
xlabel('x'); ylabel('y'); zlabel('z');
%make the math formulas look pretty with Latex
title('$z = sin(x)-sin(y)$', 'Interpreter','latex');
print -djpeg 3Dplot4.jpg;

%%
%axis equal gives a better perception
clf
[X,Y]=meshgrid(linspace(-10,10,50));
Z = sin(X)-sin(Y);
surf(X,Y,Z);
xlabel('x'); ylabel('y'); zlabel('z');
%make the math formulas look pretty with Latex
title('$z = sin(x)-sin(y)$', 'Interpreter','latex');
axis equal
print -djpeg 3Dplot5.jpg;

%%
%mesh
clf
mesh(X,Y,Z)
title('mesh')
axis equal
print -djpeg 3Dplot6.jpg;
clf









