MATLAB: How to plot a sphere using the cylinder function

cylinder

I know that I can easily plot a sphere using the sphere function, but I am trying to do it with the cylinder function. This is what I have so far, but I can't seem to get the function right.
clc;
x1 = linspace(0,pi,100);
y1 = linspace(0,1,100);
z1 = linspace(0,2,100);
[x2, y2,z2]=cylinder(x.^2+y.^2),200);
figure(2);
surf(x2, y2,z2);
xlabel('X');
ylabel('Y');
zlabel('Z');
colormap(jet)

Best Answer

x = linspace(0, 1, 20);
[X, Y, Z] = cylinder(sqrt(x .* (1 - x)));
surf(X, Y, Z);
axis equal
The first input determines the radius. Then h^2 = p*q helps.