How can I write a loop to evaluate theta at every two degrees from 0-360?

4 ビュー (過去 30 日間)
Emily Gobreski
Emily Gobreski 2016 年 6 月 11 日
編集済み: Image Analyst 2016 年 6 月 12 日
n=(360/Dth)+1
theta=0
for I=1:2:n
R=12
w=(2*pi/5)
Md=50
Thetarads= theta*pi/180
Id=(.5*Md*R^2)
Mp=75
Mb=30
alpha=0
u=.8
L=6*R
theta=0
Dth=2
thetarads=theta*pi/180
rx=(R)*cos(theta)-L*cos(180)-L
ry=(R*sin(theta))-(L*sin(180))-(R*sin(theta))
vx=(-R)*(w)*sin(theta)
vy=(R)*(w)*cos(theta)
alpha=0
ax=(-R)*alpha*sin(theta)-(R*(w^2)*cos(theta))
ay=(R)*alpha*cos(theta)-(R*w^2*sin(theta))
theta=theta+Dth
end
  2 件のコメント
Roger Stafford
Roger Stafford 2016 年 6 月 11 日
There are a number of errors or questionable items in your code:
1) Inside the for-loop you set theta = 0 so that it will never change.
2) You write sin(theta) and sin(180), and theta and (I suspect) 180 are in degrees, whereas ‘sin’ uses radian measure.
3) In the line
ry=(R*sin(theta))-(L*sin(180))-(R*sin(theta))
the R*sin(theta) terms cancel each other.
4) You set alpha = 0, so why use it in the lines for ax and ay?
5) Why have you defined Md, Id, Mp, Mb, u. They are never used.
Emily Gobreski
Emily Gobreski 2016 年 6 月 11 日
編集済み: Emily Gobreski 2016 年 6 月 11 日
thank you so much! I have no idea what I am doing. I really appreciate your time and help! what do i need to do to make sure theta changes?

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

回答 (1 件)

Steven Lord
Steven Lord 2016 年 6 月 11 日
You probably want simply to use the degree-based trig functions like sind, cosd, etc. instead of sin and cos.
  2 件のコメント
Emily Gobreski
Emily Gobreski 2016 年 6 月 11 日
thank you! how can i write it in radians and still account for the degree change?
Chad Greene
Chad Greene 2016 年 6 月 11 日
Steven's suggesting an alternative function. If you're working in degrees, you can use sind(theta) or you can use sin(theta*pi/180). They will both give the same result.

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by