How Does Symbolic Math Toolbox Define Differentiation of a Complex Function?

The doc page diff - Differentiate symbolic expression or function - MATLAB is essentially silent on how diff handles differentiation of complex functions. All it says in the Tips section is: "For complex arguments of abs and sign, the diff function formally computes the derivative, but this result is not generally valid because abs and sign are not differentiable over complex numbers."
What does "formally" mean in this context?
More specifically, consider the following:
syms f(z) Df(z) % z is complex unless assumed otherwise
The conjugate function is nowhere complex differentiable, yet
f(z) = conj(z),Df(z) = diff(f(z),z) % 1
f(z) = 
Df(z) = 
1
The magnitude-squared function is complex differentiable only at z0 = 0, yet diff returns an expression that is defined everywhere
f(z) = z*conj(z),Df(z) = diff(f(z),z) % 2
f(z) = 
Df(z) = 
Taking the previous result as correct, this result does follow from the product rule.
The magnitude function is nowhere complex differentiable, yet
f(z) = abs(z),Df(z) = diff(f(z),z) % 3
f(z) = 
Df(z) = 
This result does follow from implicit differentiation of abs(z)^2 and the previous results, if we assume the previous results are correct.
The sign function is also interesting
f(z) = sign(z),Df(z) = diff(f(z),z)
f(z) = 
Df(z) = 
That result is sensible when z is real. Given that the toobox defines @doc:sign as
f(z) = z/abs(z) % 4
f(z) = 
It could very well define the derivative in accordance with the previous results as
Df(z) = simplify((abs(z)*diff(z,z) - z*diff(abs(z),z))/abs(z)^2)
Df(z) = 
but it doesn't.
As with differentiation of real functions, complex differentiation is defined by a limit, but it seems like the toolbox is only considering that limit from one direction (at least for cases 1-3)
Case 2 can be written in terms of abs and 4 is sign and the doc page has warned those results are "not generally valid." That sounds like an understatement in these instances. And the doc is silent on case 1 (conjugation). Insofar as abs and sign can both be expressed in terms of conj, maybe the doc should replace "abs" and "sign" with "conj" in that statement (and note that functions like abs and sign can both be rewritten in terms of conj).
What does the doc mean by "fomally computes the derivative" and how is one to interpret any of these results?

Respuestas (1)

In my opinion, "fomally computes the derivative" probably means MATLAB is applying the literal, mechanical rules of algebra/calculus while completely ignoring whether the meaning of the math is actually valid on the complex plane. In other words, the symbolic diff() function only calculates form, but it does not calculate meaning.
Think of it like a spell-checker. A spell-checker can tell us that "The square root of a banana is a purple window" is a perfectly spelled sentence with correct grammar. It is formally correct. But logically, it is nonsense!
From a pure programming perspective, MATLAB will produce successful analytical outputs for functions like abs(z), abs(z)^2 or z^2 because there are no error messages, no warnings, and no red text. Without a human operating with self-human intelligence to run a Cauchy-Riemann verification script, a programmer could easily plug a diff(abs(z), z) result into a larger simulation and introduce a massive mathematical bug without ever realizing it.
Here is a basic Cauchy-Riemann verification script for a single complex variable z, by splitting the complex variable into its real and imaginary parts. Let's first test it on the function to see what a valid complex derivative looks like:
syms z complex
diff(z^2, z)
ans = 
% diff(abs(z)^2, z)
% ---------------------------
% Cauchy-Riemann verification
% ---------------------------
% Create independent, strictly real variables for x and y
syms x y real
% Split the complex variable into its real and imaginary parts
z = x + 1i*y;
% 3. Define the complex function f(z)
f = z^2 % Similar to the example on Wikipedia
f = 
% f = abs(z)^2 % If we look at |z|^2, the math becomes instantly clear to human intuition
% Expand the expression
f_split = expand(f)
f_split = 
% Group the real and imaginary parts, f = u + i*v
u = real(f_split)
u = 
v = imag(f_split)
v = 
% differentiate both components with respect to both x and y
du_dx = diff(u, x)
du_dx = 
du_dy = diff(u, y)
du_dy = 
dv_dx = diff(v, x)
dv_dx = 
dv_dy = diff(v, y)
dv_dy = 
% Test the Cauchy-Riemann Conditions for logical truth: returns 1 (True) or 0 (False)
condition1 = isAlways(du_dx == dv_dy)
condition1 = logical
1
condition2 = isAlways(du_dy == -dv_dx)
condition2 = logical
1

Categorías

Más información sobre Symbolic Math Toolbox en Centro de ayuda y File Exchange.

Productos

Versión

R2026a

Preguntada:

el 11 de Sept. de 2026 a las 2:37

Respondida:

hace 2 minutos

Community Treasure Hunt

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

Start Hunting!

Translated by