Tim Lahey wrote:

> 3. Somewhat related to #1, is the ability to make new variables/
> function names from old ones. For example, when in the Calculus of
> Variations, I'll create the variation function with a name based on
> the function to be varied (e.g., v(x,y,z,t) to \delta v(x,y,z,t)).
> I also need this to carry out my EulerLagrange calculation. To
> illustrate this, my Maple code for this is:

Dunno if it really matters, but I couldn't resist the opportunity to
translate the function in question to Maxima ...

euler_lagrange (Lagrangian, variables) := block
  ([num_list, qv_name, vel_var, qv_subs, qv_unsubs, Lagrange_subs1,
    Lagrange_subs2, dL_dqv1, dL_dqv2, dL_dqv, dL_dqvt, dL_dq, dL_dq1,
    dL_dq2, dL_dq3, q_name, q_subs, q_unsubs],

    /* guessing here that nops = length */
    num_list : makelist (i, i, 1, length (variables)),

    qv_name : map (concat, qv, num_list),
    q_name : map (concat, q, num_list),

    vel_var : map (lambda ([x], 'diff (x, t)), variables),
    /* guessing here that
     * zip(f, a, b) = [f(a[1], b[1]), ..., f(a[n], b[n])
     */
    qv_subs : map ("=", vel_var, qv_var),
    qv_unsubs : map ("=", qv_var, vel_var),

    q_subs : map ("=", variables, q_name),
    q_unsubs : map ("=", q_name, variables),

    /* guessing here that subs = subst */
    Lagrange_subs1 : subst (qv_subs, Lagrangian),
    Lagrange_subs2 : subst (q_subs, Lagrange_subs1),

    dL_dqv1 : map (lambda ([x], diff (Lagrange_subs2, x)), qv_name),
    dL_dq1 : map (lambda ([x], diff (Lagrange_subs2, x)), q_name),

    /* not sure why original has map2(subs(...)) here;
     * why not just subs ? stagger ahead anyway
     */
    dL_dq2 : subst (qv_unsubs, dL_dq1),
    dL_dqv2 : subst (qv_unsubs, dL_dqv1),
    dL_dqv : subst (q_unsubs, dL_dqv2),
    dL_dq : subst (q_unsubs, dL_dq2),
    dL_dqvt : map (lambda ([u], diff (u, t)), dL_dqv),

    [dL_dqvt, dL_dq]);

The above is untested. As you can see from the comments
I'm not sure what some (maybe most) of the Maple functions do.

What does this prove? Maybe not much, except that in this case
it's possible to do some useful expression hacking without
writing new code for Sage.

FWIW

Robert Dodier

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to