Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question
1

How to extract coefficient terms from a differential equation, as for polynomial?

asked 12 years ago

Hello all. As title, I want to extract from a differential equation the term coefficients with respect to a variable. For example:

var('x, u')
y = function('y', x)
DE = y.diff(x)*u^2 + 2*u + x

from DE I want to create a new symbolic expression with the coefficient of u^2, in this case y.diff(x). Must I convert DE to a polynomial ring? And how can I do it?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 12 years ago

calc314 gravatar image

You can use DE.coeff(u,2) to extract the coefficient of u2.

You can see a list of commands you can use with your expression DE by typing DE. and hitting the tab key.

Preview: (hide)
link

Comments

Mmmh... it really works with the simple example above, but not in the more complicated (and bad) code I was working on: var('x, u, u1, u2) f = -3*u2*(u1/u + 1/x) - 3*(u1)^2/(x*u) eta = function('eta', x, u, u1) def D(f, g) : return f.diff(x) + u1*f.diff(u) + u2*f.diff(u1) + g*f.diff(u2) D1_eta = D(eta, f) D2_eta = D(D1_eta, f) D3_eta = D(D2_eta, f) DE = D3_eta - f.diff(u)*eta - f.diff(u1)*D1_eta - f.diff(u2)*D2_eta DE.coeff(u2,3) I must do DE.collect(u2).coeff(u2,3) Furthemore if you print DE.collect(u2) terms are expanded, but not collected with respect to u2. I must do DE.collect(u2).collect(u2) It's really strange... it's a bug or my fault? I have Sage 5.1 running on Ubuntu 12.04 ...(more)

Lucas_Malor gravatar imageLucas_Malor ( 12 years ago )

I've had a similar situation with `simplify_full` where I had to apply the command twice to get the desired result. Sage uses Maxima to do these symbolic computations, but I'm not sure why the iteration is needed and whether you'd have to do this iteration if you were working in Maxima.

calc314 gravatar imagecalc314 ( 12 years ago )

I'll see if this is a bug, thank you :)

Lucas_Malor gravatar imageLucas_Malor ( 12 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: 12 years ago

Seen: 1,749 times

Last updated: Jul 14 '12