# Revision history [back]

The solve function has an optional argument solution_dict.

Using it, solutions are returned as dictionaries, which makes it easier to access the solved values of each unknown.

Here is a way to use that in the function from the question.

def polynomial_coefficient(fcn1, fcn2): a, b = SR.var('a, b') eqn1 = 2a + 2b == 0 eqn2 = 3a - b == 1 sol = solve([eqn1, eqn2], a, b, solution_dict=True)[0] return sol[a]fcn1 + sol[b]*fcn2

The solve function has an optional argument solution_dict.

Using it, solutions are returned as dictionaries, which makes it easier to access the solved values of each unknown.

Here is a way to use that in the function from the question.

def polynomial_coefficient(fcn1, fcn2):
a, b = SR.var('a, b')
eqn1 = 2a 2*a + 2b 2*b == 0
eqn2 = 3a 3*a - b == 1
sol = solve([eqn1, eqn2], a, b, solution_dict=True)[0]
return sol[a]fcn1 sol[a]*fcn1 + sol[b]*fcn2sol[b]*fcn2