Gallery
3D
3 examples. Open any of them in the editor to change it.
Code
% Drag the figure to rotate, scroll to zoom, double-click to reset.
[X, Y] = meshgrid(linspace(-3, 3, 60));
Z = peaks(X, Y);
surf(X, Y, Z)
colormap viridis
colorbar
title('peaks(x, y)')
xlabel('x'), ylabel('y'), zlabel('z')
Torus (parametric surface) Open ↗ Code
[U, V] = meshgrid(linspace(0, 2*pi, 60), linspace(0, 2*pi, 30));
R = 2; r = 0.7;
X = (R + r*cos(V)) .* cos(U);
Y = (R + r*cos(V)) .* sin(U);
Z = r * sin(V);
surf(X, Y, Z, cos(3*U) .* sin(V)) % colour by a pattern, not height
colormap turbo
axis equal
view(-30, 40)
title('A torus coloured by cos 3u · sin v')
Code
s = linspace(0, 2*pi, 600);
x = sin(s) + 2*sin(2*s);
y = cos(s) - 2*cos(2*s);
z = -sin(3*s);
plot3(x, y, z, 'LineWidth', 3)
axis equal
view(20, 55)
title('Trefoil knot')