1
$\begingroup$

What is the most efficient way to numerically compute the sine of a complex number?

Suppose I want to calculate the sine of a complex number a + bi on a computer. Suppose that a and b are both floating point numbers with a limited precision and I want to compute the real and complex parts of the sine of a + bi.

I'm sure that there are many ways to break this down, but supposing that I have functions available in a library that compute exponents and trig functions of real numbers, how can I go about computing the sine of a complex number?

$\endgroup$
2
  • $\begingroup$ That should be provided by the standard library of the language. If not, $$\sin (a+ib) = \sin a \cos (ib) + \cos a \sin (ib) = \sin a \cosh b + i \cos a \sinh b$$ should be faster and more accurate than anything you write by hand unless you're an expert. $\endgroup$ May 16, 2014 at 17:35
  • $\begingroup$ @DanielFischer, I think that should be posted as an answer. I'm working on a library in Javascript. I want it to be compatible with this new technology called asm.js (which most libraries aren't). Therefore, I needed to know how I can do this sort of computation. I think that your answer is probably best! $\endgroup$ May 16, 2014 at 17:42

2 Answers 2

2
$\begingroup$

You can use the usual trigonometric formulas ($\cos(a+b)=\cos a \cos b-\sin a\sin b$, etc.), and you also need:

$$\cos ix=\mathrm{cosh}\, x$$

$$\sin ix=i \,\mathrm{sinh}\, x$$

They are direct consequences of the definition of $e^z$ (and then trigonometric and hyperbolic functions) as a series.

Thus, for example,

$$\cos(a+ib)=\cos a\,\mathrm{cosh}\,b-i\sin a\,\mathrm{sinh}\, b$$

$\endgroup$
5
  • 1
    $\begingroup$ You mean $\sin ix = i$ sh $x$, surely? (And I would write $\sinh x$ for sh $x$.) $\endgroup$
    – TonyK
    May 16, 2014 at 17:43
  • $\begingroup$ Yes, latex typo :-) $\endgroup$ May 16, 2014 at 17:44
  • $\begingroup$ The usual abbreviation in the United States for the function $x \mapsto \frac12(e^x+e^{-x})$ is $\cosh x$, and similarly $x \mapsto \frac12(e^x-e^{-x})$ is $\sinh x$. $\endgroup$
    – MJD
    May 16, 2014 at 17:45
  • $\begingroup$ @MJD I know, but I'm french :-) Ok, I'll change this, since it's the most common in programming languages, so the most likely to be known... $\endgroup$ May 16, 2014 at 17:47
  • $\begingroup$ No need to change it; I was only adding my comment to help explain your French abbreviation. $\endgroup$
    – MJD
    May 16, 2014 at 18:02
1
$\begingroup$

$(1)$ You can always use the taylor series of the $\sin$ function namely, $$\sin(z) = z - \frac{z^3}{3!} + \frac{z^5}{5!} - \frac{z^7}{7!} + \cdots$$

$(2)$ You can also use the relationship $$e^{iz}=\cos(z)+i\sin(z),\ \sin(z)=\frac{e^{iz}-e^{-iz}}{2i}$$

$\endgroup$
5
  • $\begingroup$ I am familiar with using the Taylor series. I thought that perhaps there was a more efficient way that would perhaps involve defining the real and imaginary parts of the answer in terms of real-valued trig functions or somesuch. I am doing this in a computer program that will compute the sine of many, many complex numbers, so I'm looking for the most efficient way. $\endgroup$ May 16, 2014 at 17:34
  • $\begingroup$ @Daniel: You are right $-$ Rod's answer is irrelevant and unhelpful. $\endgroup$
    – TonyK
    May 16, 2014 at 17:38
  • $\begingroup$ @Rod: Now that's better! +1 $\endgroup$
    – TonyK
    May 16, 2014 at 17:42
  • $\begingroup$ I wouldn't call it irrelevant. I certainly could use a Taylor expansion to do this sort of calculation. I just don't know how it would compare to other ways of doing the calculation. $\endgroup$ May 16, 2014 at 20:18
  • $\begingroup$ @Daniel: It's irrelevant because you told us that you already have the trig functions over $\mathbb R$ at your disposal. $\endgroup$
    – TonyK
    May 18, 2014 at 19:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .