How do I get a graph to spiral

198 ビュー (過去 30 日間)
Brendan Clark
Brendan Clark 2021 年 4 月 6 日
コメント済み: Brendan Clark 2021 年 4 月 6 日
I'm working on creating a spiral of archimedes for a hw assignment, I'm having difficulty getting the plot to spiral properly. Right now I'm just getting a straight line. I cannot use polar plot either.
The code I have right now is:
clear variables
clc
x=linspace(0,40,2000);
k=1.5;
theta=0:(pi/8):(8*pi);
r=k*theta;
plot(theta,r)
grid on
this is what I'm ultimately supposed to be creating.

採用された回答

DGM
DGM 2021 年 4 月 6 日
Well it would be a straight line, wouldn't it? Since there's a direct linear relationship between r and theta and that's what you're plotting.
r=k*theta;
It's only a spiral if you're looking at it from the right perspective.
clear variables
clc; clf
k=1.5;
theta=linspace(0,8*pi,1000);
r=k*theta;
x=r.*cos(theta);
y=r.*sin(theta);
plot(x,y)
axis equal
grid on
  1 件のコメント
Brendan Clark
Brendan Clark 2021 年 4 月 6 日
I had actually just figured that out with a combo of the previous answer and another help page I had open.
I'm glad you posted however, because I was in the process of trying to figure out how to make the axis equal, thank you for that!

サインインしてコメントする。

その他の回答 (1 件)

KSSV
KSSV 2021 年 4 月 6 日
t = linspace(0,10*pi,5000);
r = 5. ;
c = 4 ;
x = r*cos(t) ;
y = r*sin(t) ;
z = c*t ;
comet3(x,y,z) ;
plot3(x,y,z,'Color','m','Linewidth',1) ;
title({'Parametric Equations for Spiral';'x=rcos\theta';'y=rsin\theta';'z = c\theta'}) ;
  1 件のコメント
Brendan Clark
Brendan Clark 2021 年 4 月 6 日
That formatting was able to help me at least get a circle, but ultimately I'm trying to create a 2D archimedes sprial like the one pictured above.

サインインしてコメントする。

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by