Derivative of a real function becomes complex
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Roberto Cipollone
am 2 Mai 2018
Kommentiert: Roberto Cipollone
am 3 Mai 2018
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 Kommentar
Walter Roberson
am 2 Mai 2018
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.
Akzeptierte Antwort
Walter Roberson
am 2 Mai 2018
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()
Weitere Antworten (0)
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!