Ask Your Question

Is it possible to define (or assume) the derivative of a function

asked 2016-02-25 07:49:39 -0500

ywidme gravatar image

What i would like to do is define formal symbolic functions

f1 = function('f1',latex_name = 'f_1')(x)

and set their derivative or at least be able to substitute their derivative. As an example assume I defined f1,f2,f3,f4 then I would set dx f1 = f2+f3 and what I would expect is


to output

f2(x)+ f3(x)
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2016-02-28 03:02:38 -0500

eric_g gravatar image

I think that the short answer to your question is 'no'. However, to get the output of your example, you can still define f1 as the primitive of f2+f3:

sage: f2 = function('f2', latex_name='f_2')
sage: f3 = function('f3', latex_name='f_3')
sage: f1(x) = integrate(f2(x)+f3(x), x)
sage: diff(f1(x), x)
f2(x) + f3(x)
sage: f1.derivative(x)
x |--> f2(x) + f3(x)
edit flag offensive delete link more

answered 2016-02-29 15:22:52 -0500

kcrisman gravatar image

You should be able to create a class of a function, though, and give it a custom derivative.

    # only one of derivative and tderivative should be defined
    if hasattr(self, '_derivative_') and hasattr(self, '_tderivative_'):
        raise ValueError("only one of _derivative_ or _tderivative_ should be defined.")

There are a number of examples in the src/sage/functions directory, e.g.

edit flag offensive delete link more


That's interesting! Thanks for pointing this!

eric_g gravatar imageeric_g ( 2016-03-02 03:49:40 -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

1 follower


Asked: 2016-02-25 07:49:39 -0500

Seen: 191 times

Last updated: Feb 29 '16