Ask Your Question

symbolic function from R^m to R^n

asked 2013-06-26 13:05:03 +0200

vdelecroix gravatar image


Is it possible to define functions from $\mathbb{R}^m$ to $\mathbb{R}^n$ in Sage? And then, compose them, compute their jacobian (see also this previous post), use them for change of variables, ...

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-06-26 13:31:39 +0200

tmonteil gravatar image

updated 2013-06-26 13:32:24 +0200

Is there something wrong with the following example for computing Jacobian ?

sage: var('x y')
sage: f(x, y) = (x^2 + y, x - sin(y))
sage: f.derivative()
[    (x, y) |--> 2*x       (x, y) |--> 1]
[      (x, y) |--> 1 (x, y) |--> -cos(y)]
sage: f.derivative()(x=0, y=2)
[      0       1]
[      1 -cos(2)]

Concerning composition, this is indeed more tricky, because:

sage: f(x, y).parent()
Vector space of dimension 2 over Symbolic Ring

So, you could try:

sage: g(x, y) = (2*y, x)
sage: g(f[0], f[1])    
(2*x - 2*sin(y), x^2 + y)
edit flag offensive delete link more


Thanks! For Jacobian, there is something wrong: the string is ugly.

vdelecroix gravatar imagevdelecroix ( 2013-06-26 14:47:23 +0200 )edit

Well, you can do: sage: f.derivative()(x,y) [ 2*x 1] [ 1 -cos(y)] Or even: sage: show(f.derivative()(x,y)) Agree, i should help reviewing #14567 instead ;)

tmonteil gravatar imagetmonteil ( 2013-06-26 15:21:23 +0200 )edit

Use: g(*f) to substitute in the components of f into g.

Jason Grout gravatar imageJason Grout ( 2013-06-28 12:15:38 +0200 )edit

Also, we could print the callable matrices more simply, like we print the callable vectors. Compare: f(x,y)=(3*x,y+x,sin(x)) (we print the (x,y)|--> outside of the vector). We should make a callable symbolic matrix class that prints the domain variables outside of the matrix. It would be the analog to: (and shouldn't be that hard to do).

Jason Grout gravatar imageJason Grout ( 2013-06-28 12:19:06 +0200 )edit

Also, you don't have to do var('x y') because f(x,y)=... automatically declares the variables x and y.

Jason Grout gravatar imageJason Grout ( 2013-06-28 12:20:07 +0200 )edit

answered 2013-06-29 03:39:36 +0200

Jason Grout gravatar image

Reformulating some of my comments above as an answer so they don't get lost:

To compose, you can do:

f(x,y)=(x+2*y, x^2)
g(x,y)=(sin(x), cos(x*y))

Note also that I didn't have to declare x and y to be variables; that is automatically done when they are used as inputs in an f(x,y)=... declaration.

As for printing of symbolic matrices, see my comment above. I would love if someone would write the necessary straightforward class to improve the printing.

edit flag offensive delete link more


Then open a ticket ;)

kcrisman gravatar imagekcrisman ( 2013-06-29 12:22:53 +0200 )edit
Jason Grout gravatar imageJason Grout ( 2013-07-09 06:50:27 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-06-26 13:05:03 +0200

Seen: 547 times

Last updated: Jun 29 '13