[Jprogramming] shortening a verbose expression
Henry Rich
henryhrich at gmail.com
Sun Jan 7 02:11:55 UTC 2018
Bravo.
Henry Rich
On 1/6/2018 8:26 PM, Jimmy Gauvin wrote:
> This might be easier on the eyes:
>
> vc=:_2 */\ 1 2 1 1 2 o. 5 $ o.
>
> vc 1.25,_0.55
> 0.110616 0.698401 _0.707107
>
>
> On Sat, Jan 6, 2018 at 7:05 PM, Henry Rich <henryhrich at gmail.com> wrote:
>
>> Not really any better, but you might enjoy playing with it:
>>
>> vec2 =: ((+.@:(* {:) , {.@]) +.)~/@:(^@:j.)
>>
>> Henry Rich
>>
>>
>> On 1/6/2018 5:07 PM, Jerry wrote:
>>
>>> I am a relative newbie and am trying to teach myself the intricacies by
>>> addressing a simple problem: some geometric operations on the surface of a
>>> unit sphere. The first step is to take latitude and longitude angles and
>>> create a Cartesian vector pointing from the center of the sphere to that
>>> point. I can do that via:
>>>
>>> vec =: ((1 o. }:)*(2 o. {:)),((1 o. }:)*(1 o. {:)),(2 o. }:)
>>>
>>> this verb yields the desired vector
>>>
>>> [vec o. (1.25,_0.55)
>>>
>>> 0.110616 0.698401 _0.707107
>>>
>>> +/([vec o. (1.25,_0.55))^2
>>>
>>> 1
>>>
>>> Is there a shorter, less verbose way of writing the verb 'vec'?
>>>
>>> ----------------------------------------------------------------------
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>
>>
>> ---
>> This email has been checked for viruses by AVG.
>> http://www.avg.com
>>
>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list