フィルターのクリア

Strange output using symbols in a matrix

14 ビュー (過去 30 日間)
Jason Gauthier
Jason Gauthier 2018 年 10 月 13 日
コメント済み: Jason Gauthier 2018 年 10 月 13 日
I always seem to have some weird results when using symbols in matrices. I wrote a simple function that generates a transformation matrix based on arguments.
function rot = dh_t (a,alpha, d, theta)
rot = [cos(theta) -sin(theta) 0 a;...
sin(theta)*cos(alpha) cos(theta)*cos(alpha) -sin(alpha) -d*sin(alpha);...
sin(theta)*sin(alpha) cos(theta)*sin(alpha) cos(alpha) d*cos(alpha);...
0 0 0 1]
end
When I call this function:
dh_t(0,pi/2,L1,t2)
I get an ugly output.
[ cos(t2), -sin(t2), 0, 0]
[ (4967757600021511*sin(t2))/81129638414606681695789005144064, (4967757600021511*cos(t2))/81129638414606681695789005144064, -1, -L1]
[ sin(t2), cos(t2), 4967757600021511/81129638414606681695789005144064, (4967757600021511*L1)/81129638414606681695789005144064]
[ 0, 0, 0, 1]
I stick this in my calculator where I wrote an equivalent function:
[cos(t2) sin(t2) 0 0]
[sin(t2) cos(t2) 0 0]
[0 0 1 l1]
[0 0 0 1]
Suggestions are welcome on how to handle this. Thanks!
  2 件のコメント
madhan ravi
madhan ravi 2018 年 10 月 13 日
I stick this in my calculator where I wrote an equivalent function:
What do you mean by this? can you elaborate more?
Jason Gauthier
Jason Gauthier 2018 年 10 月 13 日
Yes. It doesn't happen with my Ti-Inspire calculator.

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

回答 (2 件)

Walter Roberson
Walter Roberson 2018 年 10 月 13 日
dh_t(0,sym(pi)/2,L1,t2)
  1 件のコメント
Jason Gauthier
Jason Gauthier 2018 年 10 月 13 日
oh, that's very nice.

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


Star Strider
Star Strider 2018 年 10 月 13 日
Use the vpa (link) function.
Result = vpa(dh_t(0,pi/2,L1,t2), 3)
  3 件のコメント
Jason Gauthier
Jason Gauthier 2018 年 10 月 13 日
although that appears more to be an issue with cos/sin inaccuracies.
Star Strider
Star Strider 2018 年 10 月 13 日
I suspect that the TI-inspire is not using the extended-precision representation that the Symbolic Math Toolbox does. It may instead be using the IEEE 754 standard, and considers 6.12e-17 as essentially 0.

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

カテゴリ

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

タグ

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by