Ask Your Question
1

symbolic function from R^m to R^n

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

vdelecroix gravatar image

Hi,

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
1

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

tmonteil gravatar image

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

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

Comments

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

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

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 +0100 )edit
1

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

Jason Grout gravatar imageJason Grout ( 2013-06-28 12:15:38 +0100 )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: http://hg.sagemath.org/sage-main/src/0f8fd922eaed351e39f913f1317d319dcceb4c01/sage/modules/vector_callable_symbolic_dense.py?at=default (and shouldn't be that hard to do).

Jason Grout gravatar imageJason Grout ( 2013-06-28 12:19:06 +0100 )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 +0100 )edit
2

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

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))
f(*g)

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

Comments

Then open a ticket ;)

kcrisman gravatar imagekcrisman ( 2013-06-29 12:22:53 +0100 )edit
Jason Grout gravatar imageJason Grout ( 2013-07-09 06:50:27 +0100 )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

Stats

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

Seen: 737 times

Last updated: Jun 29 '13