Azzera filtri
Azzera filtri

Finite differences of a complex function

1 visualizzazione (ultimi 30 giorni)
carlos g
carlos g il 10 Lug 2020
Risposto: Steven Lord il 10 Lug 2020
I have a function (a complex array of values uul(:)) for which I would like to compute its derivative. I simply use central finite differences
uulder=(uul(3:end)-uul(1:end-2))./deltaeta(2:end-1)'/2;
uulderabs=(abs(uul(3:end))-abs(uul(1:end-2)))./deltaeta(2:end-1)'/2;
I plot this:
>> plot(eta,abs(uul))
>> hold on
>> plot(eta(1:end-2),abs(uulder))
>> hold on
>> plot(eta(1:end-2),uulderabs)
It seems the red curve is incorrect while the yellow one is correct. However, I would need the vector whose absolute value gives the yellow curve (and not taking absolute values beforehand like with uulderabs). I need this because with the yellow curve I am losing the real and imaginary parts and I would like to be able to use them. What is it that I am doing wrong?
  1 Commento
Benjamin Bauer
Benjamin Bauer il 10 Lug 2020
What exactly makes you think the red curve is incorrect?
Note that the red curve's values are not supposed to match the tangent slopes of the blue one: If we say the values in uul are evaluated from a function then the blue curve shows and the red curve shows which is definitely not the same as (displayed by the yellow curve).
However, if you still want some graphical validation of your derivatives you should try to plot
absuulder = real(uul.*conj(uulder))./abs(uul)
which should match the yellow curve.

Accedi per commentare.

Risposte (1)

Steven Lord
Steven Lord il 10 Lug 2020
For real numbers, the operators ' and .' give the same result.
xR = 1:10;
y1R = xR'
y2R = xR.'
isequal(y1R, y2R)
For complex numbers, they don't.
xC = complex(1:10, 10:-1:1);
y1C = xC'
y2C = xC.'
isequal(y1C, y2C)
See the documentation for either transpose or ctranspose for a brief explanation of the difference between the two.
I suspect your deltaeta is complex.

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by