Ticket #3941 (assigned defect)

Opened 5 months ago

Last modified 2 months ago

threading diff over lists to give the jacobian

Reported by: jason Assigned to: jason (accepted)
Priority: major Milestone: sage-3.4
Component: calculus Keywords:
Cc:

Description

In MMA, you can thread the derivative over lists of variables and functions to compute the Jacobian. Here's a routine that wraps the sage diff function to do it.

def diff(f,*args):
    if isinstance(f, (list, tuple)):
        return [diff(component,*args) for component in f]
    else:
        if isinstance(args[0], (list, tuple)):
            return [diff(f,variable) for variable in args[0]]
        else:
            return sage.all.diff(f,*args)

and the results:

sage: var('a,b,c,d,x,y')
sage: diff((a*x+b*y,c*x+d*y),(x,y))
[[a, b], [c, d]]

well, so the result is not really a matrix, but rather a nested list that could be indexed like a matrix or turned into a matrix in the above case.

We could write the above even more simply if we had an outer product operator:

outer_product(diff,f,vars), where f and vars were lists.

Change History

08/31/2008 08:06:45 AM changed by jwmerrill

See also #2547, asking for a symbolic gradient and hessian.

11/13/2008 10:24:25 PM changed by jason

  • owner changed from gfurnish to jason.
  • status changed from new to assigned.