Hi, everyone I am going to solve Blasius equation in a tranformed variable.
The equation looks like: U'''+2U*U''=0 U' == diff(U(y),y) Change of variable: x = (y-L)/(y+L) U = y+V I cannot implement it correctly using **subs** or **xreplace** due to some limitations(Incorrect behavior with subs and second derivatives <https://github.com/sympy/sympy/issues/7806>) Currently, I have to implement it this way: from sympy import * U,V,x,y = symbols('U,V,x,y') L = symbols('L') init_printing() get_ipython().magic(u'matplotlib inline') # Blasius equation beq = 2*Derivative(U(y),y,3)+Derivative(U(y),y,2)*U(y) Eq(beq,0) # ## substitution of variables # from y to x #new variable: x #old variable: y y2x = 2*y/(L+y)-1 # from x to y x2y = solve(y2x-x,y)[0] # ## Dictionary for change of variable sd = zip([diff(U(y),y,i) for i in range(4)],[diff(y+V(y2x),y,i).subs({y:x2y}).simplify().doit() for i in range(4)]) sd # Change of variables from high order derivative to low order ones. # # *sympy* function **replace** is used rather than **subs** which will give incorrect result. for sdi in sd[::-1]: beq = beq.replace(*sdi) beq=beq.simplify() # ## some hacks to generate code for chebfun.chebop in matlab DIFF=symbols('diff') sd2 = zip([Derivative(V(x),x,i)for i in range(4)],[DIFF(V,i) for i in range(4)]) beq2 = beq.args[-1] for sdi in sd2[::-1]: beq2 = beq2.replace(*sdi) beq2 print octave_code(beq2.subs({L:1})) My question is: is there any way to do this more tight and clean? -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/7706f861-d4b7-47ea-a705-466e0f29be14%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
