ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 18 Mar 2021 03:32:41 +0100Function composition not workinghttps://ask.sagemath.org/question/56217/function-composition-not-working/I'm experiencing some strange behavior when composing two basic functions. My OS is Windows 10. Here is an example:
sage: r=var('r')
sage: s=var('s')
sage: f(r)=r**2
sage: g(r)=r**(1/2)
sage: f(g(r))
sqrt(r)
sage: f(g(s))
s
Whenever I evaluate the functions at the variable they were defined with (or even if just the outer function was defined with it), Sage returns the inner function as the result. This seems to happen only when the two functions are inverses of each other, since it behaves as expected with $f(r)=r^2$ and $g(r)=r^{1/3}$, returning $r^{2/3}$.
Is this a known issue? Is this somehow expected behavior? Thanks for any help.tarix29Thu, 18 Mar 2021 03:32:41 +0100https://ask.sagemath.org/question/56217/Can I express an abstract, symbolic range of reals?https://ask.sagemath.org/question/51935/can-i-express-an-abstract-symbolic-range-of-reals/Hello,
I'm very new at sage.
I'd like to express a range like range(-3.0,3.0,0.02) but with symbols for all the parameters, like range(a,b,delta), that displays nicely with show(). I would like to be able to substitute in floats at some later stage.
a. I'm not sure what a conventional symbolic expression for a range of floats is
b. Not sure how to express it in SageMath.
My goal is to be able to express constructing a chain rule over a finite input range. I seem to be able to express the chaining of functions ok, but am getting stuck with what i'm calling the constant function which is this range. If I use the range(-3.0,3.0,0.02) I get swamped by the output.
P.S. I don't want to use a built-in differentiate, I'm going to use finite differences.
Cheers...banksiaboySat, 13 Jun 2020 04:03:56 +0200https://ask.sagemath.org/question/51935/Self composition of a function with symbolic variablehttps://ask.sagemath.org/question/51369/self-composition-of-a-function-with-symbolic-variable/I have a function in one variable with a placeholder variable, and would like to find the nth iterate. For example, using:
$f(z) = z^3 + az^2$, a function in variable z with placeholder coefficient a.
then I would like to see
$f(f(z)) = ( z^3 + az^2)^3 + a( z^3 + az^2)^2$
However I am struggling to perform this in sage.
$f(f)$ returns $(a*z^2 + z^3)*z^2 + z^3$
, so it substitutes for a instead of z, and declaring $f(f(z))$ returns the function only in terms of z .
How can we self compose functions with a placeholder variable for a coefficient?sbernerSun, 10 May 2020 20:55:28 +0200https://ask.sagemath.org/question/51369/How to compose two functionshttps://ask.sagemath.org/question/50113/how-to-compose-two-functions/Suppose I have a function f(x)=x^2+1
What is the command to compose it with itself twice or thrice?
I was using:
f= (x^2+1)
g= lambda t: (t^2+1)
f(*g)
or
sage: g = lambda t: (t^2+1)
sage: f = lambda x: (x^+1)
sage: f(*g(t))
or
sage: x = var('x')
sage: f=x^2+1
sage: compose(f, 3, x)
Nothing works! Also, I don't know how to use the Dynamical system code in this case here.
Also, it would be of great help if you can give me one example command for the composition of two different functions
e.g f(x)=x^2+1 and g(x)=x^3+2 if it is not obvious from the answer of the composition of the same function twice.ArnabSat, 29 Feb 2020 04:21:11 +0100https://ask.sagemath.org/question/50113/How to realize the composition of rational function mappings with Sagemath?https://ask.sagemath.org/question/44063/how-to-realize-the-composition-of-rational-function-mappings-with-sagemath/If I have two rational function mappings :
f(x,y): (x,y )------>( x^2+15x-2 / x+15, x^2y+xy+y / x^2+30x-1 );
g(x,y): (x,y )------>( x^2+20x-18 / x+20, x^2y+xy+32y / x^2-31x+14 );
how to compute the f(g(x,y)) with sagemath?xiwang0213Thu, 25 Oct 2018 05:03:33 +0200https://ask.sagemath.org/question/44063/How can I recurse a power series in two variables?https://ask.sagemath.org/question/39960/how-can-i-recurse-a-power-series-in-two-variables/ I would like very much to express, for example,
R.<x, y> = PowerSeriesRing(QQ, default_prec = 20)
g(x, g(x, g(x, x)))
Or,
f(x, f(x, f(x, f(x, f(x, f(x, f(x, f(x, f(x, f(x, f(x, f(x, (f(x, (f(x, f(x,y))))))))))))))))).expand()
In a more elegant way, for a specified number of self-compositions in one variable. I have only been able to find the sage function of composition for one variable polynomials, not for nesting two variable power series.masseygirlWed, 06 Dec 2017 01:59:43 +0100https://ask.sagemath.org/question/39960/How can I compose 2 power series in one variable with their compositional inverse get a power series in two variables?https://ask.sagemath.org/question/39739/how-can-i-compose-2-power-series-in-one-variable-with-their-compositional-inverse-get-a-power-series-in-two-variables/I would like to compose a power series $\ell$ defined in $x$ to get a power series $\ell^{-1}(\ell(x) + \ell(y))$ as a power series $f(x, y)$ in two variables, $x$ and $y$. In the code below I call l := $\ell$, and e := $\ell^{-1}$.
PREC = 20
R.<x, y> = PowerSeriesRing( QQ, default_prec=PREC )
f = exp( 1/3 * log( 1-x^3 ) )
print f
w = 1/f
l = w.integral(x)
e = l.reverse()
g = e(l(x) + l(y)) ??
I find immediately the following issue, let alone the issue of composing:
e = l.reverse()
AttributeError: 'MPowerSeriesRing_generic_with_category.element_class' object has no attribute 'reverse'
Once I have this two variable power series $f(x, y)$, I would like to output $f(x, (f(x, ..., f(x,x)))$, composed with itself $n$-times for a natural number $n$.masseygirlThu, 23 Nov 2017 06:38:05 +0100https://ask.sagemath.org/question/39739/Prevent sage from calculating a function?https://ask.sagemath.org/question/31809/prevent-sage-from-calculating-a-function/So I have some code where I would like to formally plug in a number value into a symbolic function without having sage calculate it.
For example, if I have;
var(x)
f(x) = x^2
c = 2
And then I put in f(c), I'd like it to return 2^2 and not 4. I imagine there must be a way to do this, but I can't seem to find it with googling. Any suggestions would be appreciated.Jason021Wed, 23 Dec 2015 19:15:59 +0100https://ask.sagemath.org/question/31809/How to plot composition of unit step and sin functionshttps://ask.sagemath.org/question/8894/how-to-plot-composition-of-unit-step-and-sin-functions/When i was trying to plot the function U(sin(x)) where U is the unit step function it leaves error message, but U(exp(x)) worked nicely
the error message was
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_68.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("cGxvdChoKHNpbih4KSksICh4LCAtMTAsIDEwKSk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/tmp/tmpeAn7w2/___code___.py", line 3, in <module>
exec compile(u'plot(h(sin(x)), (x, -_sage_const_10 , _sage_const_10 ))
File "", line 1, in <module>
File "/sage/local/lib/python2.6/site-packages/sage/misc/decorators.py", line 657, in wrapper
return func(*args, **kwds)
File "/sage/local/lib/python2.6/site-packages/sage/misc/decorators.py", line 504, in wrapper
return func(*args, **options)
File "/sage/local/lib/python2.6/site-packages/sage/plot/plot.py", line 3071, in plot
G = _plot(funcs, *args, **kwds)
File "/sage/local/lib/python2.6/site-packages/sage/plot/plot.py", line 3105, in _plot
funcs, ranges = setup_for_eval_on_grid(funcs, [xrange], options['plot_points'])
File "/sage/local/lib/python2.6/site-packages/sage/plot/misc.py", line 138, in setup_for_eval_on_grid
return fast_float(funcs, *vars,**options), [tuple(range+[range_step]) for range,range_step in zip(ranges, range_steps)]
File "fast_eval.pyx", line 1388, in sage.ext.fast_eval.fast_float (sage/ext/fast_eval.c:8901)
TypeError: no way to make fast_float from NonenoufalasharafMon, 16 Apr 2012 10:39:33 +0200https://ask.sagemath.org/question/8894/Iterated functional compositionhttps://ask.sagemath.org/question/8760/iterated-functional-composition/I try to translate a Maple function computing OEIS A144150 as given in [1]:
<pre>
g := proc(p) local b;
b := proc(n) option remember; local k;
`if`(n=0,1,add(binomial(n-1,k-1)*p(k)*b(n-k),k=1..n))
end end:
A144150 := (n, k) -> (g@@k)(1)(n);
seq(print(seq(A144150(n,k),k=0..8)),n=0..5);
</pre>
I am somewhat clueless how to achieve this with Sage.
Google found [2] which highlights the problem but does not give an answer.
<pre>
[1] http://oeis.org/A144150
[2] http://groups.google.com/group/sage-support/browse_thread/thread/9cda87e8889b6ead/
</pre>
petropolisThu, 01 Mar 2012 05:59:12 +0100https://ask.sagemath.org/question/8760/