Ask Your Question
1

Self composition of a function with symbolic variable

asked 2020-05-10 13:55:28 -0500

sberner gravatar image

updated 2020-05-10 14:16:07 -0500

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 $(az^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?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-05-10 14:15:18 -0500

tmonteil gravatar image

What is wrong here :

sage: var('a')
a
sage: f(z)=z^3+a*z^2
sage: f(f(z))
(a*z^2 + z^3)^3 + (a*z^2 + z^3)^2*a
edit flag offensive delete link more

Comments

Ahh, my mistake was that I was also declaring z as a variable. Why don't I need to do this? Does sage "know" that this is over the complex field?

sberner gravatar imagesberner ( 2020-05-10 14:20:08 -0500 )edit
1

No, the construction f(z)= is not Pythonic, so there is some Sage preparsing that does the job of defining the symbol z :

sage: preparse('f(z)=z^3+a*z^2')
'__tmp__=var("z"); f = symbolic_expression(z**Integer(3)+a*z**Integer(2)).function(z)'
tmonteil gravatar imagetmonteil ( 2020-05-10 14:58:57 -0500 )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: 2020-05-10 13:55:28 -0500

Seen: 59 times

Last updated: May 10