# Revision history [back]

It helps to go step-by-step. In this case, the error message "unable to convert x (=x) to an integer" is telling you that something is a symbolic variable (x) which you're trying to treat as something else:

sage: reset()
sage: var('x')
x
sage: eqn=x^2+3*x-9==0
sage: eqn
x^2 + 3*x - 9 == 0


Looks good, now we can solve:

sage: sol
[{x: -3/2*sqrt(5) - 3/2}, {x: 3/2*sqrt(5) - 3/2}]
sage: type(sol)
<type 'list'>


and you see that sol isn't a dictionary, it's a list of dictionaries. So sol[x] can't work, because it's trying to take the "x-th" element of the list, when really you want one of the entries (0 or 1, as Python/Sage starts counting from 0 instead of 1):

sage: sol[0]
{x: -3/2*sqrt(5) - 3/2}
sage: sol[0][x]
-3/2*sqrt(5) - 3/2
sage: sol[0][x].n(100)
-4.8541019662496845446137605031
sage: sol[1][x].n(100)
1.8541019662496845446137605031


Does that make sense?

It helps to go step-by-step. In this case, the error message "unable to convert x (=x) to an integer" is telling you that something is a symbolic variable (x) which you're trying to treat as something else:

sage: reset()
sage: var('x')
x
sage: eqn=x^2+3*x-9==0
sage: eqn
x^2 + 3*x - 9 == 0


Looks good, now we can solve:

sage: sol=solve(eqn,x,solution_dict=true)
sage: sol
[{x: -3/2*sqrt(5) - 3/2}, {x: 3/2*sqrt(5) - 3/2}]
sage: type(sol)
<type 'list'>


and you see that sol isn't a dictionary, it's a list of dictionaries. So sol[x] can't work, because it's trying to take the "x-th" element of the list, when really you want one of the entries (0 or 1, as Python/Sage starts counting from 0 instead of 1):

sage: sol[0]
{x: -3/2*sqrt(5) - 3/2}
sage: sol[0][x]
-3/2*sqrt(5) - 3/2
sage: sol[0][x].n(100)
-4.8541019662496845446137605031
sage: sol[1][x].n(100)
1.8541019662496845446137605031


Does that make sense?