Look at these expressions:
Even if every function and variable is real, the result is a complex number. Each step seems valid, but the sequence gives unexpected results. It seems to arise from the particular way it expresses the denominator of cos(atan2(y,x)).
Is the result valid? If not, how can I avoid this transformation?
sqrt(x^2 + y^2) = abs(x + i*y)
All this appears inside a symbolic expression (x and y are expressions too), so I can't manually rewrite them.

댓글 수: 1

When I test in Maple, I do not see the same difficulty by default, provided that I have put the assumption of 'real' in place like you did. However, in Maple if I hold off the assumption of real until after the diff() then I am able to replicate the problem.

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

 채택된 답변

Walter Roberson
Walter Roberson 2018년 5월 2일

3 개 추천

I think the error is in the cos(atan2(y,x)) step generating the abs.
Even though for real values the expression abs(x+1i*y) is equivalent to sqrt(x^2+y^2), when you diff() the abs() version under the assumption that you might be working with complex values, you violate the branch-cut assumptions and get a complex branch cut, and when you substitute real values into that afterwards you are still on the complex branch cut.
The work-around is to
rewrite(ans, 'sqrt')
after the cos() and before the diff()

댓글 수: 1

Or maybe it is related to abs(.) being not an holonomic function. So the two expressions are not equivalent under differentiation. Strange behaviour.
Anyway, the workaround does perfectly the job. Thanks

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by