MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

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.



  • Prev by Date: Re: Re: Strange Syntax problem
  • Next by Date: eps color export
  • Previous by thread: text bounding box size
  • Next by thread: Re: Legendre transform