On 28.01.2013 01:08, Aaron Meurer wrote: > On Jan 27, 2013, at 6:34 AM, "Alexey U. Gudchenko" <[email protected]> wrote: > >> >> Additionally to Stefan's answer about sympy core , I introduce the >> example how it may be implemented concretely. >> >> There is the tested code in the atachment of it. >> (I can create PR, but I don't know where will it be better to put in the >> sympy modules) >> >> And there is the '__call__' magic-method used instead of the implicit >> multiplication as aplly-like method. >> >>>>> Dx = DiffOperator(x) >>>>> myD = (a*Dx + Dx**3) # construct diff operator >>>>> myD(x**4) # apply this operator. >> 4*a*x**3 + 24*x >> >> >> For matrices it is some more complicated >> >>>>> I = Matrix([[0, -1], [1, 0]]) >>>>> myD = I*Dx # construct diff >>>>> myD(x**2) # apply >> >> Derivative([x**2, 0] >> [ 0, x**2], x) >> >> >> Here I don't know how Derivative can be automatically applied for the >> Matrix expression. > > Well just as application of Dx isn't really multiplication, neither is > application of the matrix operator. So a subclass of Matrix will be > needed here. > > Aaron Meurer > >>
Yes, for the matrix differential operators with matrices which are depended of the variables of differentiation we must think. But for the "constant" matrix (which is independent of the variable x) I don't quite understand what kind of subclass of Matrix is needed: which is related to differential operator or differential method of matrix itself. In order to avoid duplicating code, I think, we must use that for the matrix M which is independent of the variable x the following is: M Dx = Dx M and at the same time for the applying this operator we only care that differential operator would always be to the left of the expression A (x) to which it is applied. So for the (constant) matrix differential operator myD = (M Dx) (M Dx) A(x) = (Dx M) A(x) = Dx (M A(x)) Is it right? This is done automatically in presented diff_operator.py (only for the matrices M which are independent of the variable x) Therefore for the (M Dx) A(x) we can compute M A(x) firstly and then only a problem in this case, that I can't compute derivative of the matrix expression diff( M*A(x), x) This was the question. In the case when M(x) is depended of x, we must of course keep it always on the left in th expression M(x) Dx != Dx M(x) (this is not realized in attached code above) So a subclass of Matrix will be needed only in this case. Or rather, internal support in DiffOperator expression must be implemented for this case. Alexey Gudchenko >> >> -- >> Alexey Gudchenko >> >> On 26.01.2013 02:49, ruoyu zhang wrote: >>>>>> p = DifferentialOperator(t) >>>>>> a * p * f(t) >>> Derivative(f(t), t)*a >>> >>> p is a DifferentialOperator, when it multiply with some expression at >>> right side, it calculates the derivative of the expression. >>> >> >> -- >> 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?hl=en. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> <diff_operator.py> > -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
