On Dec 8, 2007, at 9:13 AM, Ondrej Certik wrote:
> >> My MATLAB code isn't available at the moment. It shouldn't be a >> problem translating it to Python. The problem is translating the >> Maple >> code that derives the element matrices to Sage. I'm not exactly >> thrilled >> with the design of the MATLAB code, but it works for my problems. I'd >> probably make it object-oriented when converting it to Python. > > And which exact symbolic features are still missing in Sage, if any? I > mean, was the problem just that python is > different than Matlab, or just because something in Sage should be > improved? I make heavy use of Maple's op command and hastype (I find the op sequences of the integrals and integrands). The code is pretty messy so I'll refrain from posting it here at the moment. I also make use of the fact you can create new variable names by appending to old ones in my Euler- Lagrange code. This code is much faster than Maple's code. My Euler-Lagrange code is as follows. In Maple this executes about 2 orders of magnitude faster than the built-in one (0.1 seconds vs. 10 seconds) and it preserves the order. I assume that time is the independent variable, but modifying that is easy. The conversion to new variables is because Maple can't take derivatives with respect to variables, only symbols. 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. Tim. --~--~---------~--~----~------------~-------~--~----~ 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://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~----------~----~----~----~------~----~------~--~---