Inverse cosine of complex numbers

I'm trying to get the inverse cosine of a complex number. Using the definition given in the help of acos(z) produces a different result than directly using acos. See below for the code snippet. Can someone help me out?
format LONGENG
z = 0.625820036622262+1.576125391478034E-055i;
res1 = acos(z)
d = z + i*sqrt(1-(z*z))
res2 = -i*log(d)

回答 (1 件)

Andrew Reibold
Andrew Reibold 2014 年 10 月 9 日
編集済み: Andrew Reibold 2014 年 10 月 9 日

0 投票

I know why!
You were close, but you didn't quite replicate the definition in the documentation correctly.
This is how you would write it.
d = z + i*sqrt(1-z*z)
res2 = -i*log(d)
Using this corrected definition, I get approximately 0.894613863 + ~0i for both answers.
First Method Solution: 0.894613863926113 - 2.02075780910344e-55i
Second Method Solution: 0.894613863926114 + 1.11022302462516e-16i
Bother of the i values are near negligible in magnitude relative to the real part.
Hope this helped!
-Andrew

4 件のコメント

Sriram
Sriram 2014 年 10 月 9 日
Well, I don't know what you corrected. I get the same answers as yours. My question is why the imaginary part is different: -2.02075780910344e-55i vs. 1.11022302462516e-16i?
For my problem, I do not care about approximately being same, I want precisely the same answer from both methods. How is the internal MATLAB implementation different than the definition?
Titus Edelhofer
Titus Edelhofer 2014 年 10 月 9 日
You can't expect them to be exactly equal: since the computation of the imaginary part involves the real part, you can expect the result only be precise up to the numerical roundoff (which is in fact what Andrew got as result, namely
eps(0.89)
ans =
1.1102e-16
Titus
Sriram
Sriram 2014 年 10 月 9 日
Can we know how acos is implemented within MATLAB for them to get -2.02075780910344e-55i? Clearly it must some numerical implementation -
Andrew Reibold
Andrew Reibold 2014 年 10 月 10 日
編集済み: Andrew Reibold 2014 年 10 月 10 日
For some reason I thought your square root function was only taking the square root of z^2. Unless you edited the question, I just made an honest mistake saying you typed it wrong I guess.

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

カテゴリ

ヘルプ センター および File ExchangeData Type Identification についてさらに検索

質問済み:

2014 年 10 月 9 日

編集済み:

2014 年 10 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by