Ask Your Question
4

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

asked 2016-02-25 14:49:39 +0100

ywidme gravatar image

updated 2022-10-27 20:17:22 +0100

FrédéricC 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

f1.derivative(x)

to output

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

2 Answers

Sort by » oldest newest most voted
3

answered 2016-02-28 10:02:38 +0100

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
3

answered 2016-02-29 22:22:52 +0100

kcrisman gravatar image

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

https://github.com/sagemath/sage/blob...

    # 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. https://github.com/sagemath/sage/blob...

edit flag offensive delete link more

Comments

That's interesting! Thanks for pointing this!

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

Stats

Asked: 2016-02-25 14:49:39 +0100

Seen: 715 times

Last updated: Feb 29 '16