Re: Legendre transform

*To*: mathgroup at smc.vnet.net*Subject*: [mg64315] Re: [mg64312] Legendre transform*From*: Bob Hanlon <hanlonr at cox.net>*Date*: Sat, 11 Feb 2006 03:32:45 -0500 (EST)*Reply-to*: hanlonr at cox.net*Sender*: owner-wri-mathgroup at wolfram.com

Off[Solve::ifun]; Off[InverseFunction::ifun]; Clear[legendreTransform]; legendreTransform[f_, x_Symbol, y_Symbol]:= Module[{d=D[f, x], transform}, transform/; (transform=(-f+x*d)/.Solve[y==d, x]//Last; FreeQ[transform,Solve]&& FreeQ[transform,InverseFunction])]/;!(x===y); legendreTransform[Exp[x], x, y] y*Log[y] - y legendreTransform[%, y, x] E^x Bob Hanlon > > From: Tobin Fricke <fricke at ocf.berkeley.edu> To: mathgroup at smc.vnet.net > Subject: [mg64315] [mg64312] Legendre transform > > As an exercise in learning Mathematica, and also as a computational and > pedagogical tool for myself, I'm attempting to implement a function to > compute the Legedre transform[1] of an expression. > > The procedure is, given a function f(x): > > 1. compute y(x) = f'(x) and solve for x(y) > 2. the legendre transform is g(y) = -f(x(y)) + x(y) y > > Here's my first attempt: > > legendreTransform[f_, x_, y_] := Block[{}, > solutions = Solve[y == D[f, x], x]; > x[k_] := x /. First[solutions]; > -(f /. x -> x[y]) + x[y] y] > > For instance, it correctly gives the transform of xLog[x]-x as e^x: > > Simplify[legendreTransform[x Log[x] - x, x, y], > Assumptions -> {Element[y, Reals]}] > > This seems to work, though (1) things go horribly wrong if x==y, and (2) > errors aren't handled at all--for instance, it should detect whether the > Solve[] fails, etc. > > Another attempt is written in a such a way as to operate on *functions* > rather than expressions. To me this seems like the preferred way, but > maybe it isn't: > > legendreTransform[f_] = Block[{x, y}, > x[y_] = x /. First[Solve[y == f'[x], x]]; > Function[y, -f[x[y]] + x[y] y]] > > Any hints/critiques/etc appreciated. I'd like to end up with a version > that will let me take the legendreTransform with respect to an arbitrary > argument of a function with arbitrarily many arguments. > > thanks, > Tobin > > [1] http://en.wikipedia.org/wiki/ Legendre_transform#Legendre_transformation_in_one_dimension > >