Ask Your Question

# symbolic function from R^m to R^n

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 close merge delete

## 2 Answers

Sort by » oldest newest most voted

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, f)
(2*x - 2*sin(y), x^2 + y)

more

## Comments

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

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 ;)

1

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).

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

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.

more

## Your Answer

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

Add Answer

## Stats

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

Seen: 350 times

Last updated: Jun 29 '13