On Wed, Sep 23, 2009 at 11:06 AM, Ryan Krauss <ryanli...@gmail.com> wrote: > So, either i am missing something or maybe I am not reinventing the wheel. > In the end, I am dumping the output of cse to a text file that I save as a > Python module and later reuse with numpy/scipy, simply by importing the > module. Here is an example: > > def det_two_piece(s, params): > if type(params) == dict: > params = SLFR_TMM.SLFR_params(**params) > EI = params.EI > L1 = params.L > L2 = params.L2 > mu = params.mu > beta1=pow((-1*s*s*L1**4*mu/EI),0.25) > d1_1 = 0.5*(cos(beta1)+cosh(beta1)) > d2_1 = 0.5*(sinh(beta1)-sin(beta1)) > d3_1 = 0.5*(cosh(beta1)-cos(beta1)) > d4_1 = 0.5*(sin(beta1)+sinh(beta1)) > beta2=pow((-1*s*s*L2**4*mu/EI),0.25) > d1_2 = 0.5*(cos(beta2)+cosh(beta2)) > d2_2 = 0.5*(sinh(beta2)-sin(beta2)) > d3_2 = 0.5*(cosh(beta2)-cos(beta2)) > d4_2 = 0.5*(sin(beta2)+sinh(beta2)) > a_m = params.a_m > a_L = params.a_L > a_I = params.a_I > a_r = params.a_r > k_clamp = params.k_clamp > c_clamp = params.c_clamp > #-------------------------------- > # > # below here, eveything is autogenerated > # > #-------------------------------- > x0 = s**2 > x1 = c_clamp*s > x2 = k_clamp + x1 > x3 = 1/x2 > x4 = 1/L1 > x5 = 1/EI > x6 = 1/beta1 > x7 = a_L - a_r > x8 = d1_1*x3 > x9 = L1*d4_1*x5*x6 > x10 = x8 + x9 > x11 = x4**(-2) > x12 = x6**2 > x13 = d3_1*x11*x12*x5 > x14 = L1*d4_1*x3*x6 > x15 = x13 + x14 > x16 = 1/x11 > x17 = 1/x12 > x18 = EI*d3_1*x16*x17*x3 > x19 = beta1*d2_1*x4 > x20 = x18 + x19 > x21 = L2**(-2) > x22 = beta2**2 > x23 = x21**(1/2) > x24 = x16**(-3/2) > x25 = x17**(-3/2) > x26 = a_I*x0 > x27 = a_m*a_r*x0*x7 > x28 = x26 - x27 > x29 = x23**3 > x30 = x22**(3/2) > x31 = a_L*x10 > x32 = x15 + x31 > x33 = a_m*a_r*x0*x10 > x34 = a_m*x0*x15 > x35 = x33 + x34 > x36 = x35 - x20 > x37 = x10*x28 > x38 = EI*x19*x3 > x39 = -x20 > x40 = -a_L*x39 > x41 = -x34*x7 > x42 = d1_1 + x37 + x38 + x40 + x41 > x43 = d2_1*x12*x24*x5*x6 > x44 = a_L*x13 > x45 = x43 + x44 > x46 = -x45 > x47 = a_m*x0*x43*x7 > x48 = L1*d4_1*x6 > x49 = d3_1*x11*x12*x28*x5 > x50 = a_L*d1_1 > x51 = x48 + x49 + x50 > x52 = x47 - x51 > x53 = x30**(-1/3) > x54 = a_m*a_r*x0*x13 > x55 = a_m*x0*x43 > x56 = x54 + x55 > x57 = d1_1 - x56 > det = (d1_2*x52 - L2*d4_2*x53*x57 + EI*d3_2*x21*x22*x46 - > beta2*d2_2*d3_1*x11*x12*x23)*(-d1_2*x36 + beta2*d2_2*x23*x42 + > EI*d3_2*x10*x21*x22 + EI*beta2*d4_2*x22*x29*x32) + (d1_2*x42 - > L2*d4_2*x36*x53 + EI*beta2*d2_2*x10*x23 + EI*d3_2*x21*x22*x32)*(d1_2*x57 - > beta2*d2_2*x23*x52 - EI*d4_2*x29*x30*x46 + d3_1*d3_2*x11*x12*x21*x22) > return det > > So, I need the sympy results converted to text. For now I am very naively > just doing things like: > curline = ' '*4+ '%s = %s' % (var, expr) > where var and expr are from the list of tuples returned as the first output > of cse.
I think I got it finally. Yes, you are doing it right, only make sure to import the division from future. I was just looking at how lambdify works, and it works essentially the same way. Do you think you could polish your code generation module and submit it as a patch to sympy, together with documentation and tests? It would be very useful to lots of people. I would help you get it polished. Ondrej --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sympy?hl=en -~----------~----~----~----~------~----~------~--~---