Finite differences of a complex function

1 回表示 (過去 30 日間)
carlos g
carlos g 2020 年 7 月 10 日
回答済み: Steven Lord 2020 年 7 月 10 日
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 件のコメント
Benjamin Bauer
Benjamin Bauer 2020 年 7 月 10 日
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.

サインインしてコメントする。

回答 (1 件)

Steven Lord
Steven Lord 2020 年 7 月 10 日
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.

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by