Ask Your Question
1

Can desolve_system return dict?

asked 2011-07-29 20:54:02 +0100

Ondra gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2011-08-01 16:42:22 +0100

Mike Hansen gravatar image

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}
edit flag offensive delete link more

Comments

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?

Ondra gravatar imageOndra ( 2011-08-01 21:24:18 +0100 )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

Stats

Asked: 2011-07-29 20:54:02 +0100

Seen: 355 times

Last updated: Aug 01 '11