Essays/Sine

From J Wiki
Jump to: navigation, search

Some ways of computing the sine of a number.


Primitive

The sine qua non of the various ways.

s0=: 1&o.

Exponential

 \sin z = {{e^{iz} - e^{-iz}} \over 2i}

s1a=: 0j2 %~ ^@j. - ^@-@j.
s1b=: ^ .: - &.j.

Trigonometric Identities

s2a , s2b , and s2c implement, respectively,   \sqrt{1-\cos^2 z}  and   \cos z \,\tan z  and   - i \,\sinh\, iz

s2a=: (0&o.) @ (2&o.)
s2b=: */ @ (2 3&o.)
s2c=: 5&o. &. j.

Derivative and Integral

s3a=: -@(2&o.) d.  1
s3b=:    2&o.  d. _1

Power Series

s4a=: 2p1&|@] ([: -/ ^ % !@]) >:@:+:@:i.@[
s4b=: [`(! %~ 0 1 0 _1 {~ 4&|) t. T. _

   10 s4a 1
0.841471
   1 o. 1
0.841471

   10 s4a 1j2
3.16578j1.9596
   1 o. 1j2
3.16578j1.9596

   (1&o. = s4b) 0.1*i:5
1 1 1 1 1 1 1 1 1 1 1

Hypergeometric Series

The phrase '' H. 1.5 is limit of the the hypergeometric series with upper parameter the empty vector and lower parameter the number 1.5.

s5=: * '' H. 1.5@(%&_4)@*:

Infinite Product

From Abramowitz & Stegun 4.3.89 (converges slowly):

 \;\; \sin z = z \prod_{n=1}^\infty \left( 1 - {z^2 \over {n^2 \pi^2}} \right)

s6=: ] * */"1 @: -. @: *: @: (] % o.@>:@i.@[)

   100 s6 1
0.84232
   1 o. 1
0.841471

   100 200 400 800 s6"0 ] 1j2
3.14831j1.9664 3.15702j1.96302 3.16139j1.96131 3.16358j1.96046
   1 o. 1j2
3.16578j1.9596

Continued Fraction

From C.D. Olds, Continued Fractions, MAA New Mathematical Library, 1963, page 138.

s7=: 4 : 0
 n=. x
 s=. *:y
 (%`+)/y,1,s, ,(p-s),.p*s [ p=. */"1] 2+i.n,2
)
   6 s7 0.5
0.479426
   1 o. 0.5
0.479426
   | (6&s7 - 1&o.) 0.5
3.88578e_15

   20 s7 1j2
3.16578j1.9596
   1 o. 1j2
3.16578j1.9596
   | (20&s7 - 1&o.) 1j2
6.28037e_16



See also


Contributed by Roger Hui.