I didn't understand your hint about magnitude and phase angle, but look at the
new rcos and rsin below. (They involve the tolerant comparison internal to |
Residue, which appears needed for a satisfactory 0j1 exp i: 5 4 .)
NB. sin =: 1&o. * 1p1 ~:!.0 |
NB. cos =: 2&o. * 0.5p1 1.5p1 -.@(e.!.0)~ |
rsin =: 1&o. * 0 ~: 1p1 | ]
rcos =: 2&o. * 0 ~: 1p1 | 0.5p1 -~ ]
re =: 9&o.
im =: 11&o.
mexp=: ^...@re * (rcos j. rsin)@im
exp =: mexp : (mexp@(^...@[ * ]))
sin =: 0j_1r2 * exp@(0j1*]) - exp@(0j_1*])
cos =: 1r2 * exp@(0j1*]) + exp@(0j_1*])
0j1 exp i. 5 4
1 0j1 _1 0j_1
1 0j1 _1 0j_1
1 0j1 _1 0j_1
1 0j1 _1 0j_1
1 0j1 _1 0j_1
sin ,. 0j1 + 2p1 * i. 5
0j1.1752
0j1.1752
0j1.1752
0j1.1752
0j1.1752
exp 0j1p1 + 0j2p1 * i. 5
_1 _1 _1 _1 _1
Roger Hui wrote:
> By considering 10 12 o. x (magnitude and phase angle)
> in x^y, you may be able to get a more general solution,
> dispensing with the need for the constant 0.5p1+o.i.32 .
>
>
>
> ----- Original Message -----
> From: Kip Murray <[email protected]>
> Date: Monday, May 25, 2009 21:01
> Subject: Re: [Jchat] Clean elementary functions?
> To: Chat forum <[email protected]>
>
>> Here is what I settled on, taking Roger's suggestions and adding mine:
>>
>> rsin =: 1&o.
>> * (1p1 * i. 32) -
>> .@(e.!.0)~ | NB. real sine
>> rcos =: 2&o. * (0.5p1 + 1p1 * i. 32) -
>> .@(e.!.0)~ |
>> re =: 9&o.
>> im =: 11&o.
>>
>> mexp=: ^...@re * (rcos j. rsin)@im
>>
>> exp =: mexp : (mexp@(^...@[ * ]))
>>
>> sin =: 0j_0.5 * exp@(0j1*]) -
>> exp@(0j_1*]) NB. complex sine
>>
>> cos =: 0.5 * exp@(0j1*]) +
>> exp@(0j_1*])
>> Then
>>
>> 0j1 exp i. 5 4
>> 1 0j1 _1 0j_1
>> 1 0j1 _1 0j_1
>> 1 0j1 _1 0j_1
>> 1 0j1 _1 0j_1
>> 1 0j1 _1 0j_1
>>
>> sin ,. 0j1 + 2p1 * i. 4
>> 0j1.1752
>> 0j1.1752
>> 0j1.1752
>> 0j1.1752
>>
>> exp ,. 1 + 0j2p1 * i. 4
>> 2.71828
>> 2.71828
>> 2.71828
>> 2.71828
>>
>> 1p1*31 32
>> 97.3894 100.531
>>
>> 0.5p1 + 1p1*31 32
>> 98.9602 102.102
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm