how to avoid conj

82 visualizaciones (últimos 30 días)
sanam
sanam el 5 de Jun. de 2019
Comentada: Walter Roberson el 7 de En. de 2022
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 comentarios
Mehran Norouzi
Mehran Norouzi el 7 de En. de 2022
try this.
a = sym('a','real')
John D'Errico
John D'Errico el 7 de En. de 2022
@sanam - Please don't answer your question with a comment. Moved this to a comment:
"and I have used "real" in defining syms"

Iniciar sesión para comentar.

Respuestas (1)

John D'Errico
John D'Errico el 7 de En. de 2022
Editada: John D'Errico el 7 de En. de 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 comentario
Walter Roberson
Walter Roberson el 7 de En. de 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

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by