return any angle to (0 to 2pi) range

124 ビュー (過去 30 日間)
Osama Alkurdi
Osama Alkurdi 2020 年 2 月 18 日
コメント済み: James Tursa 2020 年 2 月 19 日
I have a cetain angle let us say x
and I want matlab to change x to become within 0 and 2pi range
example: if x=3pi
then the new value of x have to be pi

採用された回答

James Tursa
James Tursa 2020 年 2 月 18 日
編集済み: James Tursa 2020 年 2 月 18 日
The short answer:
mod(x,2*pi)
The long answer for this particular mod operation, is that if you want to get the same answer for trig calculations for large inputs that MATLAB does, you need to do the mod differently:
atan2(sin(x),cos(x)); % effectively mod(x,2*pi)
E.g.,
>> x = 10
x =
10
>> y = mod(x,2*pi)
y =
3.716814692820414
>> sin(x)
ans =
-0.544021110889370
>> sin(y)
ans =
-0.544021110889370
>> x = 1e25
x =
1.000000000000000e+25
>> y = mod(x,2*pi)
y =
0
>> sin(x)
ans =
-0.305257800135130
>> sin(y)
ans =
0
>> z = atan2(sin(x),cos(x))
z =
-0.310209139287907
>> sin(z)
ans =
-0.305257800135130
Using the atan2( ) approach to doing the mod(x,2*pi) operation results in effectively the same angle that MATLAB uses for the trig operations.
  2 件のコメント
Osama Alkurdi
Osama Alkurdi 2020 年 2 月 18 日
how is the remain of the division of 2pi is what I was looking for?
can you explain it?
please!
James Tursa
James Tursa 2020 年 2 月 19 日
I don't understand your question. The remainder of the division is the result of the mod operation.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by