First time here? Check out the FAQ!

Ask Your Question
4

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

asked 9 years ago

ywidme gravatar image

updated 2 years ago

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)
Preview: (hide)

2 Answers

Sort by » oldest newest most voted
3

answered 9 years ago

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)
Preview: (hide)
link
3

answered 9 years ago

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...

Preview: (hide)
link

Comments

That's interesting! Thanks for pointing this!

eric_g gravatar imageeric_g ( 9 years ago )

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: 9 years ago

Seen: 744 times

Last updated: Feb 29 '16