Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question
1

symbolic function from R^m to R^n

asked 11 years ago

vdelecroix gravatar image

Hi,

Is it possible to define functions from Rm to Rn in Sage? And then, compose them, compute their jacobian (see also this previous post), use them for change of variables, ...

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 11 years ago

tmonteil gravatar image

updated 11 years ago

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)
Preview: (hide)
link

Comments

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

vdelecroix gravatar imagevdelecroix ( 11 years ago )
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 ( 11 years ago )
1

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

Jason Grout gravatar imageJason Grout ( 11 years ago )

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 ( 11 years ago )

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 ( 11 years ago )
2

answered 11 years ago

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.

Preview: (hide)
link

Comments

Then open a ticket ;)

kcrisman gravatar imagekcrisman ( 11 years ago )

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: 11 years ago

Seen: 783 times

Last updated: Jun 29 '13