Re: [Jprogramming] The farmer's fence

2013-02-23 Thread km
Without getting into calculus of variations, we can think of combining the rectangular chicken yard with its mirror image on the other side of the barn wall. The result is a rectangle of perimeter 200. We saw that the corresponding largest area rectangle was a 50 by 50 square. So perhaps the

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread km
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

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread Alex Giannakopoulos
Checked the ellipses, turns out the maximum area is a circle after all, provided the wall is at least 200/π m. The area would be ±= 1591.549 m², unless anyone else knows better. -- For information about J forums see http://www.jsof

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread David Ward Lambert
Right! u Area returns abscissa, area That, along with incorrectly placed parens were errors. I'll replace the 1 dimensional amoeba with Brent's method, relax the tolerances, and see what happens. But not now. Thank you! NB. don't do this! too much output. cubic =: (p.&([smoutput)~ _4&{.)~ (-@

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread Linda Alvord
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---

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread Raul Miller
I was thinking that raindrop formation on windows would suggest some shape that is approximately circular. If we have a half circle, the circle's radius should be R=: 100%1p1 and the half circle's area should be: (o.R^2)%2 1591.55 So if there's a better shape it must have a larger area. I

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread Eldon Eller
Old and senile as I am, this looks to me like a problem in calculus of variations.See, e.g., en. wikipedia.org/wiki/Calculus_of_variations. You are not likely to get the solution by guessing that the shape is elliptical, or catenary, or parabolic, etc. I am too old and lazy to try to solve it m

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread km
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

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread Henry Rich
In amoeba, minindx comes from minindx =. tryerr i. minval =. <./ tryerr =. uverb simptry which should be bulletproof if uverb returns a scalar. You could try putting something like assert. (,3) -: $tryerr after that line to see if uverb is returning junk. (It's not clear to me that Area r

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread Ric Sherlock
Kip, Alternative formulations for your adverb that require fewer calculations of u y. Max1 =: 1 : 0 ((= >./)@:u # ] ,. u) y ) Max2 =: 1 : 0 fnres=. u y where=. (= >./) fnres where # y ,. fnres ) I'd be interested in a tacit implementation of one of the adverbs Max above. I came up wit

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread Linda Alvord
A should give an average. The roots are 50 0 . Shouldn't the average be 25 rather than 1 2 ? Linda -Original Message- From: programming-boun...@forums.jsoftware.com [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of km Sent: Saturday, February 23, 2013 6:45 PM To: programm

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread David Ward Lambert
Barn/fence problem, which shape holds maximum area? See Mouse on moon problem http://projecteuler.net/problem=314 which I haven't solved. Let's build a system to test an arbitrary function. A symmetrical figure has maximal area. Proof---a preferred figure would be preferred in reflection and the

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread km
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" 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

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread Linda Alvord
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 1

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread Alex Giannakopoulos
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

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread km
Borrowing ideas from Raul, I like Max =: 1 : 0 max =. >./ u y where =. max = u y where # y ,. u y ) which identifies the max and where it occurs: *: Max i:2 _2 4 2 4 (4 - *:) Max i:2 0 4 Sent from my iPad On Feb 23, 2013, at 1:04 PM, Jose Mario Quintana wrote: > I did not

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread Jose Mario Quintana
I did not see your second post! area=. ] * 50 - %&2 area(max=. (>./) @:) 0 to 100 1250 max >./@: On Sat, Feb 23, 2013 at 1:46 PM, km wrote: > Can we have an adverb Max so that f Max y finds the maximum of f on > the list y ? > > Sent from my iPad > > > On Feb 23, 2013, at 12:03

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread km
Can we have an adverb Max so that f Max y finds the maximum of f on the list y ? Sent from my iPad On Feb 23, 2013, at 12:03 PM, Aai wrote: > With some math in J > > x : length barn side > -->the other rectangle side is then > -: 100 - x > > i.o.w. we have > A = x (50 - x/2) > > w

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread km
Nicely done. The "Harvard Calculus" recommends tables, graphs, formulas, and words as problem-solving tools, and J can help with tables and graphs. About Roger's question, I am inclined to guess a half-ellipse for maximum area, but it's just a guess. --Kip Sent from my iPad On Feb 23, 2013

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread Aai
With some math in J x : length barn side -->the other rectangle side is then -: 100 - x i.o.w. we have A = x (50 - x/2) with J 0 1 +//.@(*/) 50 _0.5 0 50 _0.5 first derivative 0 50 _0.5&p. d. 1 50 _1&p. second derivative 0 50 _0.5&p. d. 2 _1"0 --> a maximum for 1{:: p. 5

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread Jose Mario Quintana
When I read it I thought the problem was to find the largest area as a function of the size of the existing barn wall. If size is zero or less then the area is (*:100%4); if it is (100%3) or larger the the area is (*:100%3); and the interesting part is in between. The function, I think, is: (

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread Raul Miller
On Sat, Feb 23, 2013 at 12:37 PM, Raul Miller wrote: > Plotting these values, we see that 50 meters corresponds to the apex > of a parabola, and there's no need to consider further where the > maxima is at. More specifically, 1250 square meters corresponds to the apex of a parabola when plotted a

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread Raul Miller
As a first pass, let's consider integer valued lengths for the lengths of one of the fences. For simplicity, let's include cases where the area is zero. L1=: i.101 Since I allowed this fence to be 100 meters in length, that means that the other two sides are equal length and use the remainder

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread km
You can get a larger area 30*40 by using 30 for the east-west dimension. Sent from my iPad On Feb 23, 2013, at 9:40 AM, Roger Hui wrote: > The largest area obtains when it's a square and that area is: > > *: 100%3 > .11 > > i.e. the length of the barn wall is 100%3 meters and so are th

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread Dan Bron
When I read this, the first thing that popped into my mind was "I thought the rule of thumb was that for a given perimeter, a circle encloses the maximal area". This led me down a path of thought which lasted throughout morning shower, and has left me with three things: (1) a realization that m

Re: [Jprogramming] The farmer's fence

2013-02-23 Thread Roger Hui
The largest area obtains when it's a square and that area is: *: 100%3 .11 i.e. the length of the barn wall is 100%3 meters and so are the lengths of the other 3 sides. Exercise for the reader: What is the largest area that can be enclosed with 100 meters of fence and one side of the bar

[Jprogramming] The farmer's fence

2013-02-23 Thread km
Use J to solve the farmer's fence problem: A farmer with 100 meters of wire fence wants to make a rectangular chicken yard using an existing barn wall for one of the north-south sides. What is the largest area he can enclose if he uses the 100 meters of fence for the other three sides, and wha