Heron de alejandria
Heron de alejandria

Reputation: 55

How to plot 3D in octave

Hi I'm starting to use Octave and need help on how to plot x²+y² = 1. I know that the figure is a cylinder. I tried:

x= -10:0.1:10; y = -10:0.1:10; t = x²+y²;

but it won't work.

Upvotes: 0

Views: 1618

Answers (1)

Ash
Ash

Reputation: 4718

For this particular situation, you can just use the cylinder function.

cylinder([a,b])

will plot a cylinder whose radius at z==0 will be equal to a, and will vary continuously and smoothly until its radius at z==1 reaches b. In you case, you need to set a and b to 1, which is what happens by default when you call cylinder().

Now this will plot the cylinder with only z values in [0,1]. If you want to customize that range, you can just get the output from the function like this:

[xx yy zz]=cylinder([1,1]);

And now you can use this to obtain the plot that you want. For example,

surf(xx,yy,zz.*10);hold on; surf(xx,yy,-zz.*10);

will produce this:

enter image description here

Upvotes: 1

Related Questions