Ask Your Question

Collecting coefficients of derivatives

asked 2017-07-10 09:41:23 -0500

Ursula gravatar image

I have a complicated expression involving derivatives of a function, and I'd like to collect all of the first, second, third, etc. derivatives. For example, my expression starts:

a1*a2*a3*x*f(x) + a1*a2*x^2*diff(f(x), x) + a1*a3*x^2*diff(f(x), x) + a2*a3*x^2*diff(f(x), x)

and I would like to rewrite that part as

    a1*a2*a3*x*f(x) + (a1*a2*x^2*+ a1*a3*x^2+ a2*a3*x^2)*diff(f(x), x)

How do I tell Sage to do this?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-07-10 12:25:14 -0500

calc314 gravatar image

Try this:

p=a1*a2*a3*x*f(x) + a1*a2*x^2*diff(f(x), x) + a1*a3*x^2*diff(f(x), x) + a2*a3*x^2*diff(f(x), x)
edit flag offensive delete link more


Note that this only collects first derivatives: to collect the second, third, etc. derivatives you'd have to do that explicitly (and know how high your derivatives go).

Ursula gravatar imageUrsula ( 2017-07-18 07:55:53 -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


Asked: 2017-07-10 09:41:23 -0500

Seen: 56 times

Last updated: Jul 10