how to avoid conj
110 次查看(过去 30 天)
显示 更早的评论
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 个评论
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
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)]'
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)].'
See the help for transpose, as compared to ctranspose.
help transpose
help ctranspose
If you use the conjugate transpose, MATLAB will do what you told it to do, that is, take the conjugate.
1 个评论
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)]'
"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)
is_it_real(y)
function tf = is_it_real(SYM)
tf = isAlways(imag(SYM) == 0);
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Assumptions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!