| 1 | initial version |
Alternate answer : use the .function() method of a expression :
sage: str="x**3"
sage: g=eval(str).function(x)
sage: g
x |--> x^3
sage: g(3)
27
Alternate to this alternate : ûexec (you will also need preparse to be able to define a symbolic function) :
sage: str2="h(x)=x**2"
sage: exec(preparse(str2))
sage: h
x |--> x^2
sage: h(3)
9
BTW :
sage: preparse(str2)
'__tmp__=var("x"); h = symbolic_expression(x**Integer(2)).function(x)'
HTH,
| 2 | No.2 Revision |
Alternate answer : use the .function() method of a expression :
sage: str="x**3"
sage: g=eval(str).function(x)
sage: g
x |--> x^3
sage: g(3)
27
Alternate to this alternate : (you will also need ûexecexecpreparse to be able to define a symbolic function) :
sage: str2="h(x)=x**2"
sage: exec(preparse(str2))
sage: h
x |--> x^2
sage: h(3)
9
BTW :
sage: preparse(str2)
'__tmp__=var("x"); h = symbolic_expression(x**Integer(2)).function(x)'
HTH,
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.