# substitute function for an array of functions Hello, I have an array of functions defined as

arr = [function("y%d" % i,x) for i in [0..(2)]]


I also have a function of function

def square(x):
return(x*x)


If I use substitute_function on the function of function it works.

temp(x)=sin(x)
square(arr).substitute_function(y0,temp)


However, the following command does not work,

temp(x)=sin(x)
square(arr).substitute_function(arr,temp)


The reason I think is that arr has an argument by y0 does not. Is it possible to use substitute_function where the arguments have arguments?

edit retag close merge delete

Sort by » oldest newest most voted

The problem is that the value of arr is y0(x), which is an expression consisting of a function evaluated at x. That's not the kind of functions that substitute_function deals with. You can use subs for that:

sage: square(arr).subs(arr==temp(x))
sin(x)^2


You are not the first person who get tripped up by the confusing fact that function('f',x) doesn't return a function but a function evaluated at (something). To get something that actually is a function, use function('f'). You can still evaluate that at x by writing function('f')(x). See http://trac.sagemath.org/ticket/17447 .

more