Ask Your Question
0

substitute function for an array of functions

asked 2015-11-09 14:38:01 -0500

Shashank gravatar image

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[0]).substitute_function(y0,temp)

However, the following command does not work,

temp(x)=sin(x)
square(arr[0]).substitute_function(arr[0],temp)

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

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-11-09 15:29:50 -0500

nbruin gravatar image

The problem is that the value of arr[0] 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[0]).subs(arr[0]==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 .

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-11-09 14:38:01 -0500

Seen: 163 times

Last updated: Nov 09 '15