Ask Your Question

Revision history [back]

When you run the solve command, the function returns a list of expressions, that are equalities. It does not touch the Python variables a and b which continue to point to the symbols a and b. Those are symbols, not numbers, so it is normal that they do not have any numerical value.

How to extract the values provided by the solve fucntion ?

The simplest way, is first to return the solutions as dictionaries, not as symbolic equalities, by using the solution_dict=True option:

sage: s = solve([7.0==a*sqrt(16)/(1+b/16.0),22==a*sqrt(4)/(1+b/4)],a,b, solution_dict=True)
sage: s
[{b: -592/169, a: 231/169}]

Here, you see that there is only one solution:

sage: s[0]
{b: -592/169, a: 231/169}

You can extract the value for a as follows:

sage: s[0][a]
231/169

and take its numerical value:

sage: s[0][a].n()
1.36686390532544

When you run the solve command, the function returns a list of expressions, that are equalities. It does not touch the Python variables a and b which continue to point to the symbols a and b. Those are symbols, not numbers, so it is normal that they do not have any numerical value.

How to extract the values provided by the solve fucntion function ?

The simplest way, is first to return the solutions as dictionaries, not as symbolic equalities, by using the solution_dict=True option:

sage: s = solve([7.0==a*sqrt(16)/(1+b/16.0),22==a*sqrt(4)/(1+b/4)],a,b, solution_dict=True)
sage: s
[{b: -592/169, a: 231/169}]

Here, you see that there is only one solution:

sage: s[0]
{b: -592/169, a: 231/169}

You can extract the value for a as follows:

sage: s[0][a]
231/169

and take its numerical value:

sage: s[0][a].n()
1.36686390532544