First time here? Check out the FAQ!

Ask Your Question
0

Collecting coefficients of derivatives

asked 7 years ago

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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 7 years ago

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)
p.collect(diff(f(x),x))
Preview: (hide)
link

Comments

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

Stats

Asked: 7 years ago

Seen: 915 times

Last updated: Jul 10 '17