> EulerLagrange := proc(Lagrangian::anything, variables::list) > local 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: > # create a list of indices from 1 to the number of variables > # used in the formulation > num_list := [seq(i,i=1..nops(variables))]: > > # Define a list of generalized velocity and position variables > qv_name := map2(cat,qv,num_list): > q_name := map2(cat,q,num_list): > > # Equate the time derivatives of the system variable to the > # generalized velocities and also define the reverse mapping > vel_var := map(diff,variables,t): > qv_subs := zip(equate,vel_var,qv_name): > qv_unsubs := zip(equate,qv_name,vel_var): > > # Equate the generalized positions to the system variables > # and define the reverse mapping > q_subs := zip(equate,variables,q_name): > q_unsubs := zip(equate,q_name,variables): > > # Convert the Lagrangian to the generalized position and velocity > variables > Lagrange_subs1 := subs(qv_subs,Lagrangian): > Lagrange_subs2 := subs(q_subs,Lagrange_subs1): > > # Differentiate the Lagrangian with respect to the > # generalized velocities and positions > dL_dqv1 := map2(diff,Lagrange_subs2,qv_name): > dL_dq1 := map2(diff,Lagrange_subs2,q_name): > > # Revert back to the system variables > dL_dq2 := map2(subs,qv_unsubs,dL_dq1): > dL_dqv2 := map2(subs,qv_unsubs,dL_dqv1): > dL_dqv := map2(subs,q_unsubs,dL_dqv2): > dL_dq := map2(subs,q_unsubs,dL_dq2): > dL_dqvt := map(diff,dL_dqv,t): > > # Return the two components of the Euler-Lagrange Equation > return (dL_dqvt, dL_dq): > end proc: > > The equate function used in zip is defined as: > equate := (x,y)->x=y: > > I used it over `=` because it is slightly faster since Maple doesn't > have > to convert equate to a function. > > I'm happy to work with someone to convert things over to Sage, but I > can't > seem to find a number of things I'm used to in Maple.
Awesome, nice application. Could you please post here some examples of usage? Correct input and output, for three or four cases, so that I can easily see what exactly the input and output should look like. I'll then think how to port this to Sage. Note: I'll be on mountains the next week, so I might do it later. Ondrej --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] 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://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~----------~----~----~----~------~----~------~--~---
