Plotting 3D parameterised curve help

1 visualizzazione (ultimi 30 giorni)
Jenny Briggs
Jenny Briggs il 14 Mar 2016
Modificato: Star Strider il 14 Mar 2016
I want to plot the curve:
r(r, θ) = (rcos(θ), rsin(θ), θ), 0 ≤ r ≤ 1, 0 ≤ θ ≤ 2π.
But I'm not really sure how to go about it.
I have tried this:
r = linspace(0,1);
theta = linspace (0,2.*pi);
x = r*cos(theta);
y = r*sin(theta);
z = theta;
plot(x,y,z)
However it keeps resulting in error.
Any help would be greatly appreciated, thanks

Risposte (1)

Star Strider
Star Strider il 14 Mar 2016
Modificato: Star Strider il 14 Mar 2016
Since ‘r’ and ‘theta’ have the same number of elements (by default 100 with linspace), you can use element-wise multiplication:
r = linspace(0,1);
theta = linspace (0,2*pi);
x = r.*cos(theta);
y = r.*sin(theta);
z = theta;
figure(1)
plot3(x, y, z)
grid on
That should do what you want (plot an Archimedes spiral).

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by