Plotting 3D parameterised curve help

3 vues (au cours des 30 derniers jours)
Jenny Briggs
Jenny Briggs le 14 Mar 2016
Modifié(e) : Star Strider le 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

Réponses (1)

Star Strider
Star Strider le 14 Mar 2016
Modifié(e) : Star Strider le 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