On Aug 25, 2008, at 10:32 PM, Robert Dodier wrote:
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)),
Yes, nops gets the number of terms in the list.
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),
zip merges two lists. So, you'd get terms vel_var[1]=qv_var[1] in the case of the first list (qv_subs).
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),
Probably. What I'm doing is replacing all the functions with symbols so I can carry out the derivative with respect to these symbols which is these next two lines (I hope).
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 */
The map2(subs(...)) is because Maple has two different map commands based upon which argument the map is over. In this case, we want to differentiate Lagrange_subs2 with respect to each of qv_name and q_name. So, we're mapping over the second argument in Maple. The syntax is different in Maxima, it appears.
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),
Now, we reverse the symbol substitutions to get the functions back.
dL_dqvt : map (lambda ([u], diff (u, t)), dL_dqv),
I presume this just differentiates each term with respect to t.
[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.
The difficulty for me is that this is pure Maxima, so I'm not sure how to mix this with Sage code. That said, thanks. It's good to know that I can do this in Maxima. Cheers, Tim.
smime.p7s
Description: S/MIME cryptographic signature