Can desolve_system return dict?

I know the parameter solution_dict=True for solve

but quick try for desolve_system(equations, unknowns, ics=initials, solution_dict=True) gives an error

desolve_system() got an unexpected keyword argument 'solution_dict'.

Is there a way?

edit retag close merge delete

Sort by » oldest newest most voted Unfortuantely, desolve_system doesn't take a solution_dict parameter -- you can do desolve_system?? to see that it doesn't take that keyword argument. Luckily, it's easy to make such a function that returns the solutions in a dictionary.

def desolve_system_dict(*args, **kwds):
use_dict = kwds.pop('solution_dict', False)
solution = desolve_system(*args, **kwds)
if use_dict:
return dict((eq.lhs(), eq.rhs()) for eq in solution)
else:
return solution

Then you can use it like this:

sage: t = var('t')
sage: x = function('x', t)
sage: y = function('y', t)
sage: de1 = diff(x,t) + y - 1 == 0
sage: de2 = diff(y,t) - x + 1 == 0
sage: desolve_system_dict([de1, de2], [x,y])
[x(t) == (x(0) - 1)*cos(t) - (y(0) - 1)*sin(t) + 1,
y(t) == (x(0) - 1)*sin(t) + (y(0) - 1)*cos(t) + 1]
sage: desolve_system_dict([de1, de2], [x,y], solution_dict=True)
{y(t): (y(0) - 1)*cos(t) + (x(0) - 1)*sin(t) + 1,
x(t): -(y(0) - 1)*sin(t) + (x(0) - 1)*cos(t) + 1}
more

yes, this solves it, so thanks much; but anyway, this is a reasonable thing to want from desolve_system, so do you think I should file a bug/feature request for desolve_system to accept solution_dict parameter?