The problem goes away if you use {: instead of }. in your definition of r .
r1 =: [: > [: {: p.
r1 0 100 _2
50 0
a r1 0 100 _2
25
The problem you had is caused by the fact that }. applied to a vector always
has a vector result and is solved by the fact that {: applied to a vector
always has a scalar result. Someone else will have to explain why opening ,
<50 0 has a different result from opening <50 0 , and also explain the
relevance of the difference. At least I can make the problem go away!
Kip
Sent from my iPad
On Feb 23, 2013, at 10:34 PM, "Linda Alvord" <[email protected]> wrote:
> My first line select the two roots:
>
> r=: 13 :'> }. p. y'
> r 0 100 _2
> 50 0
>
> These are the roots:
>
> Now find the axis of symmetry x value (the average of the roots,
>
> a=: 13 :'(+/y)%#y'
> a 50 0
> 25
>
> So if I apply a to r 0 100 _2 I expect 25. I get 1 2
>
>
>
>
> -----OriginalaMessage-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of km
> Sent: Saturday, February 23, 2013 9:53 PM
> To: [email protected]
> Subject: Re: [Jprogramming] The farmer's fence
>
> Linda, if you enter 50 0 and then enter 1 2 $ 50 0 the printed results
> appear the same, but the first has two items and the second only one item.
> What do you expect the average of a one-item array to be? Can you figure
> out how to use rank to get what you want from r 0 100 _2 ?
>
> Sent from my iPad
>
>
> On Feb 23, 2013, at 6:21 PM, "Linda Alvord" <[email protected]> wrote:
>
>> A should give an average. The roots are 50 0 .
>>
>> Shouldn't the average be 25 rather than 1 2 ?
>>
>> Linda
>>
>> -----Original Message-----
>> From: [email protected]
>> [mailto:[email protected]] On Behalf Of km
>> Sent: Saturday, February 23, 2013 6:45 PM
>> To: [email protected]
>> Subject: Re: [Jprogramming] The farmer's fence
>>
>> r 0 100 _2
>> 50 0
>> $r 0 100 _2
>> 1 2
>>
>> Sent from my iPad
>>
>>
>> On Feb 23, 2013, at 4:35 PM, "Linda Alvord" <[email protected]>
> wrote:
>>
>>> The roots of a polynomial:
>>>
>>> r=: 13 :'> }. p. y'
>>> r 0 100 _2 :
>>> 50 0
>>> r
>>> [: > [: }. p.
>>>
>>>
>>> The average of the roots or x coordinate of axis of symmetry:
>>> a=: 13 :'(+/y)%#y'
>>> a 50 0
>>> 25
>>> a
>>> +/ % #
>>>
>>> Find the maximum:
>>>
>>> 0 100 _2 p. 25
>>> 1250m
>>>
>>> Sadly this doesn't work:
>>>
>>> a r 0 100 _2
>>> 50 0
>>>
>>> Any idea why not?
>>>
>>> Linda
>>>
>>>
>>> -----Original Message-----
>>> From: [email protected]
>>> [mailto:[email protected]] On Behalf Of Alex
>>> Giannakopoulos
>>> Sent: Saturday, February 23, 2013 3:28 PM
>>> To: J Programming forum
>>> Subject: Re: [Jprogramming] The farmer's fence
>>>
>>> Nice little gotcha there, assuming that the shape will be a square,
>>> since a square maximizes the contained area for a rectangle, while
>>> forgetting that the wall gives you extra perimeter for free,
>>> depending on
>> the shape.
>>>
>>> By the same analogy I'd tackle Roger's version of the problem, i.e.
>>> find ANY shape that will maximize the area:
>>> Again, I suspect that going for a (semi)circle might be essentially
>>> the same gotcha.
>>>
>>> I haven't got time to code it at the moment, but I'd investigate an
>>> (half) ellipse and also a parabola.
>>> Will need some integration though, to find the expression for the
>>> length of their curves.
>>> ---------------------------------------------------------------------
>>> - For information about J forums see
>>> http://www.jsoftware.com/forums.htm
>>>
>>> ---------------------------------------------------------------------
>>> - For information about J forums see
>>> http://www.jsoftware.com/forums.htm
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm