abdelkader
abdelkader

Reputation: 71

simplifying composite function (diff) in maxima (chain rule for differentiation)

How can the following formula be simplified in Maxima: diff(h((x-1)^2),x,1) Mathematically it should be : 2*(x-1)*h'((x-1)^2) But maxima gives : d/dx h((x-1)^2)

Upvotes: 2

Views: 220

Answers (1)

Robert Dodier
Robert Dodier

Reputation: 17576

Maxima doesn't apply the chain rule by default, but there is an add-on package named pdiff (which is bundled with the Maxima installation) which can handle it.

pdiff means "positional derivative" and it uses a different, more precise, notation to indicate derivatives. I'll try it on the expression you gave.

(%i1) load ("pdiff") $

(%i2) diff (h((x - 1)^2), x);    
                                  2
(%o2)               2 h   ((x - 1) ) (x - 1)
                       (1)

The subscript (1) indicates a first derivative with respect to the argument of h. You can convert the positional derivative to the notation which Maxima usually uses.

(%i3) convert_to_diff (%);
                                     !
                        d            !
(%o3)      2 (x - 1) (----- (h(g485))!               )
                      dg485          !              2
                                     !g485 = (x - 1)

The made-up variable name g485 is just a place-holder; the name of the variable could be anything (and if you run this again, chances are you'll get a different variable name).

At this point you can substitute for h or x to get some specific values. Note that ev(something, nouns) means to call any quoted (evaluation postponed) functions in something; in this case, the quoted function is diff.

(%i4) ev (%, h(u) := sin(u));
                                      !
                       d              !
(%o4)     2 (x - 1) (----- (sin(g485))!               )
                     dg485            !              2
                                      !g485 = (x - 1)
(%i5) ev (%, nouns);
                                  2
(%o5)                2 cos((x - 1) ) (x - 1)

Upvotes: 2

Related Questions