Ideally the matrix expressions would let you do this better. I don't think differentiation is fully implemented with them, though.
Aaron Meurer On Sun, Apr 20, 2014 at 8:33 PM, Peter Eastman <[email protected]>wrote: > I'm just learning Sympy, so I apologize if this is a beginner question. > I'm trying to figure out how to use intermediate variables when simplifying > expressions. > > Here's a simple example of the sort of thing I'm trying to do. Suppose I > have a vector v=(v1,v2,v3). Next I define u to be a unit vector parallel > to v: u=(u1,u2,u3)=v/|v|. And then I want to compute the derivative > du1/dv1. I can do it like this: > > >>> v = Matrix([symbols('v1 v2 v3')]) > >>> u = v/sqrt(v.dot(v)) > >>> u[0].diff(v[0]) > > which produces the output > > -v1**2/(v1**2 + v2**2 + v3**2)**(3/2) + 1/sqrt(v1**2 + v2**2 + v3**2) > > That's a very complicated way of writing it, because it's fully expanded > out in terms of the individual components of v. It could be written much > more simply as (1-u1**2)/|v|. But how do I get Sympy to figure that out? > How do I create intermediate variables like u and v, tell it how they're > defined in terms of v1, v2, etc., and then tell it to perform whatever > transformations among them leads to the simplest expression? > > Thanks! > > Peter > > -- > 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 http://groups.google.com/group/sympy. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/99e49e60-9db5-4ad3-af0d-449369e4d6ac%40googlegroups.com<https://groups.google.com/d/msgid/sympy/99e49e60-9db5-4ad3-af0d-449369e4d6ac%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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 http://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2BTFA0e2kCRueSjsossED_744DxS3Nhhx%3D%2BViNkmWb41Q%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
