Strange result from symbolic processing

조회 수: 7 (최근 30일)
Marco
Marco 2012년 11월 23일
Hello,
I created this variables, some symbolic, some not:
alpha = [pi/2 0 0];
a = sym('[0 a2 a3]');
d = [0 0 0];
theta = sym('t', [1,3]);
initializing....
C = (zeros(1, 2, 2));
and I create the element (:,:,1) as:
C(:,:,1) = [(cos(theta(1))) (-sin(theta(1)))*cos(alpha(1))];
but it returns me this error:
The following error occurred converting from sym to
double:
Error using mupadmex
Error in MuPAD command: DOUBLE cannot convert the input
expression into a double array.
If the input expression contains a symbolic variable, use
the VPA function instead.
so I tried to set:
C = vpa(zeros(1, 2, 2));
and so it returns a strange result
C(:,:,1) =
[ cos(t1), -(4967757600021511*sin(t1))/81129638414606681695789005144064]
but if cos(pi/2)=0 it should be
(-sin(theta(1)))*cos(alpha(1)) = 0
what is that long (and wrong) number ?

채택된 답변

Walter Roberson
Walter Roberson 2012년 11월 23일
alpha = [pi/2 0 0];
does not define alpha(1) as the theoretical Pi/2. Instead, it defines alpha(1) as the double precision approximation to pi/2, which is not exactly Pi/2 and so cos() of it is not exactly 0.
Better use
alpha = sym('[pi/2 0 0]');

추가 답변 (1개)

Marco
Marco 2012년 11월 23일
But I need to multiply a numeric and a symbolic. If Alpha array is a symbolic it will return me (-sin(t1))*cos(pi/2)
  댓글 수: 1
Marco
Marco 2012년 11월 23일
Sorry, you are right. Thanks

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by