how to avoid conj

110 次查看(过去 30 天)
sanam
sanam 2019-6-5
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