how to avoid conj

80 vues (au cours des 30 derniers jours)
sanam
sanam le 5 Juin 2019
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 commentaires
Mehran Norouzi
Mehran Norouzi le 7 Jan 2022
try this.
a = sym('a','real')
John D'Errico
John D'Errico le 7 Jan 2022
@sanam - Please don't answer your question with a comment. Moved this to a comment:
"and I have used "real" in defining syms"

Connectez-vous pour commenter.

Réponses (1)

John D'Errico
John D'Errico le 7 Jan 2022
Modifié(e) : John D'Errico le 7 Jan 2022
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 commentaire
Walter Roberson
Walter Roberson le 7 Jan 2022
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

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by