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 ends would join correctly. Method: use a root finder to find the half length of barn wall that matches half the length of the fence. Return the corresponding area. On top of this an optimization gets the best coefficients for related curves, for instance the cubics (_4{.C1,C2,C3)&p. In Mathematica, if f[x] describes the fence shape then the path length integral is Int[Sqrt[D[f[x],x]^2+1],{x,0,upperLimit}] and we want to find upperLimit such that the integral returns 50. PathLengthIntegrand =: ((D.1)(%:@:>:@:*:@:))("0) [ PathLengthIntegrand i.3 NB. looks good. 1.41421 1.41421 1.41421 NB.Integrate with limits 0 to X, find the value of X NB.for which the length of fence is 50. load'math/misc/integrat' load'math/misc/amoeba' NB. amoeba is a no-fuss machine PathLength =: adverb def '{. u PathLengthIntegrand integrate (0 , y)' AreaFixed =: adverb define NB. y ignored, returns half (barn wall length and pasture area) assert 0 = u 0 NB. touches barn wall 'Y ERREST' =. (*:@:(50-u PathLength)amoeba (<30))0,:50[y Y , {. u integrate (0 , Y) ) [AreaFixed 50 NB. right isosceles triangle 35.3554 625.001 Area =: adverb define NB. y are the x argument for u assert 0 = y u 0 NB. touches barn wall 'Y ERREST' =. (*:@:(50- (y&u) PathLength)amoeba (<30)) 0,:50 Y , {. y&u integrate (0 , Y) ) cubic =: (p.~ _4&{.)~ NB. 0 6 -: 1 2 3 cubic 0 1 cubic Area 1 0 0 NB. still line y=x 35.3553 625 NB. negative because amoeba optimizes (-@:cubic Area amoeba (<30)) 4 3 ?@$ 0 NB. runs a short while |index error | simplex=.(minindx {simptry)_1}simplex ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm