how to avoid conj

조회 수: 83 (최근 30일)
sanam
sanam 2019년 6월 5일
댓글: Walter Roberson 2022년 1월 7일
Hello everyone
I have a symbolic vector ,
Xprime=[sin(theta1)*sin(theta2) ,sin(theta1)*cos(theta2) ,cos(theta1)*sin(theta2), cos(theta1)*cos(theta2) ,sin(theta1), cos(theta1) ,sin(theta2) ,cos(theta2)]';
I don't know why Matlab displays:
Xprime =
conj(sin(theta1))*conj(sin(theta2))
conj(cos(theta2))*conj(sin(theta1))
conj(cos(theta1))*conj(sin(theta2))
conj(cos(theta1))*conj(cos(theta2))
conj(sin(theta1))
conj(cos(theta1))
conj(sin(theta2))
conj(cos(theta2))
in the output.
how can I avoid such a problem?
Thank u for answering my question
  댓글 수: 2
Mehran Norouzi
Mehran Norouzi 2022년 1월 7일
try this.
a = sym('a','real')
John D'Errico
John D'Errico 2022년 1월 7일
@sanam - Please don't answer your question with a comment. Moved this to a comment:
"and I have used "real" in defining syms"

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

답변 (1개)

John D'Errico
John D'Errico 2022년 1월 7일
편집: John D'Errico 2022년 1월 7일
syms theta theta1 theta2
Xprime=[sin(theta1)*sin(theta2) ,sin(theta1)*cos(theta2) ,cos(theta1)*sin(theta2), cos(theta1)*cos(theta2) ,sin(theta1), cos(theta1) ,sin(theta2) ,cos(theta2)]'
Xprime = 
Did you use a transpose in there? (Yes.) Even though you told MATLAB that the variables are real, they are still called inside functions and operations, where it does not see that the result of those functions is ALWAYS real.
The fact is, the ' operator is a CONJUGATE transpose. So if you don't want a conjugate, then you need to use the .' operator. As you can see here, the conjugate is no longer present.
Xprime=[sin(theta1)*sin(theta2) ,sin(theta1)*cos(theta2) ,cos(theta1)*sin(theta2), cos(theta1)*cos(theta2) ,sin(theta1), cos(theta1) ,sin(theta2) ,cos(theta2)].'
Xprime = 
See the help for transpose, as compared to ctranspose.
help transpose
.' Transpose. X.' is the non-conjugate transpose. B = TRANSPOSE(A) is called for the syntax A.' when A is an object. See MATLAB Operators and Special Characters for more details. See also CTRANSPOSE, PERMUTE, PAGETRANSPOSE. Documentation for transpose doc transpose Other functions named transpose categorical/transpose gpuArray/transpose codistributed/transpose quaternion/transpose datetime/transpose RandStream/transpose digraph/transpose sym/transpose dlarray/transpose tabular/transpose duration/transpose
help ctranspose
' Complex conjugate transpose. X' is the complex conjugate transpose of X. B = CTRANSPOSE(A) is called for the syntax A' (complex conjugate transpose) when A is an object. See MATLAB Operators and Special Characters for more details. See also TRANSPOSE, PAGECTRANSPOSE. Documentation for ctranspose doc ctranspose Other functions named ctranspose categorical/ctranspose imaqdevice/ctranspose codistributed/ctranspose instrument/ctranspose datetime/ctranspose laurmat/ctranspose digraph/ctranspose quaternion/ctranspose dlarray/ctranspose RandStream/ctranspose duration/ctranspose serial/ctranspose gpuArray/ctranspose sym/ctranspose icgroup/ctranspose tabular/ctranspose imaqchild/ctranspose
If you use the conjugate transpose, MATLAB will do what you told it to do, that is, take the conjugate.
  댓글 수: 1
Walter Roberson
Walter Roberson 2022년 1월 7일
John, you did not tell MATLAB that the symbols are real. If you do then the conj does not appear in the output.
syms theta theta1 theta2 real
Xprime=[sin(theta1)*sin(theta2) ,sin(theta1)*cos(theta2) ,cos(theta1)*sin(theta2), cos(theta1)*cos(theta2) ,sin(theta1), cos(theta1) ,sin(theta2) ,cos(theta2)]'
Xprime = 
"Even though you told MATLAB that the variables are real, they are still called inside functions and operations, where it does not see that the result of those functions is ALWAYS real. "
No, assumptions follow the symbolic variable in the symbolic engine; functions know that the variable is real if they bother to ask the symbolic engine.
syms x real
syms y
is_it_real(x)
ans = logical
1
is_it_real(y)
Warning: Unable to prove 'imag(y) == 0'.
ans = logical
0
function tf = is_it_real(SYM)
tf = isAlways(imag(SYM) == 0);
end

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

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by