Agreed-it can be put together nicely- and can be sorted out without the
assumption of integral values
how about: A=: (100-2x)*x =100*x -2**:x
dA/dx=100-4x=0at the maximum (d^2A/dx^2 is negative)
or p.100 _4(simpler to use x=:100%4)
giving x=25 for one side (50 for the other)
If the fence is 103m long
p.103 _4or x=:103%4
┌──┬─────┐
│_4│25.75│
└──┴─────┘
25.75* 103-+:25.75
1326.125m^2
J can handle this problem in several ways-some quite elegant- however it
becomes trivial using calculus.
I think that looking at the math before programming is the way to go-as
J can home in on a solution without testing a lot of values.
Don Kelly
On 23/02/2013 9:37 AM, Raul Miller wrote:
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 of the
fencing:
L2=: -: 100-L1
And, since this is a rectangular fence, the areas are:
A=: L1*L2
The largest area found so far is, thus:
>./,A
1250
This corresponds to:
(1250=A)#L1,.L2
50 25
One side is 50 meters, and the other sides are half that.
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.
FYI,
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm