I just uploaded a patch (needs review!) to

http://trac.sagemath.org/sage_trac/ticket/8866

that lets a user do some natural things with vector-valued functions.
I'm posting here to call for any feedback on the syntax:

f(x,y) = tuple or list

Here are some examples:

sage: T(r,theta)=[r*cos(theta),r*sin(theta)]
sage: T
((r, theta) |--> r*cos(theta), (r, theta) |--> r*sin(theta))
sage: T.diff() # Jacobian matrix
[   (r, theta) |--> cos(theta) (r, theta) |--> -r*sin(theta)]
[   (r, theta) |--> sin(theta)  (r, theta) |--> r*cos(theta)]
sage: diff(T) # Jacobian matrix
[   (r, theta) |--> cos(theta) (r, theta) |--> -r*sin(theta)]
[   (r, theta) |--> sin(theta)  (r, theta) |--> r*cos(theta)]
sage: T.diff().det() # Jacobian
(r, theta) |--> r*sin(theta)^2 + r*cos(theta)^2

sage: r(t)=[cos(t),sin(t)]
sage: parametric_plot(r(t), (t,0,2*pi))

sage: f(x,y)=x^2+y
sage: f.diff() # gradient
((x, y) |--> 2*x, (x, y) |--> 1)
sage: f.diff().diff() # Hessian matrix
[(x, y) |--> 2 (x, y) |--> 0]
[(x, y) |--> 0 (x, y) |--> 0]

sage: # multivariable 2nd derivative test
sage: f(x,y)=x^2*y+y^2+y
sage: f.diff() # gradient
((x, y) |--> 2*x*y, (x, y) |--> x^2 + 2*y + 1)
sage: solve(list(f.diff()),[x,y])
[[x == -I, y == 0], [x == I, y == 0], [x == 0, y == (-1/2)]]
sage: f.diff(2)  # Hessian matrix
[(x, y) |--> 2*y (x, y) |--> 2*x]
[(x, y) |--> 2*x   (x, y) |--> 2]
sage: f.diff(2)(x=0,y=-1/2)
[-1  0]
[ 0  2]
sage: f.diff(2)(x=0,y=-1/2).eigenvalues()
[-1, 2]
sage: # we have a saddle point

I made it so that the syntax

f(x,y) = tuple or list

makes a vector with the base ring of callable symbolic expressions. Are there any comments on this syntax? I think it's pretty natural, and it's not allowed right now.

I think this will make the computations in a calc 3 class much more natural, for example.

Thanks,

Jason


--
To post to this group, send an email to [email protected]
To unsubscribe from this group, send an email to 
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to