# use output of solve() without 'var == '

Is there a way to use the values of solve() without having that pesky 'var == ' in front of it?

in   h = x^2-9; h
out     x |--> x^2 - 9
in   sols = solve(h == 0, x); sols
out     [x == -3, x == 3]
in   sols
out     x == -3
in   h(sols)
out     (x == -3)^2 - 9


What the heck is that last line?!

Is there a way to extract the value of sols for use without needing to copy/paste the value?

edit retag close merge delete

Sort by » oldest newest most voted An other way:

solve returns a list of equations.

You can get the value with .rhs() ( right hand side )

h(x) = x^2-9
sols = solve(h == 0, x); print sols
x0 = sols.rhs()
h(x0)


Further you can use python dictionaries:

h(x) = x^2-9
sols = solve(h(x), x,solution_dict=True); print sols
h(sols[x])

more

rhs() is exactly what I was lookin for - extracting the value of the solution out of the equation. Now I don't have to hardcode numbers :D sols is x==3 not a substitution command.

h = x^2-9; h
sols = solve(h == 0, x); sols
h.subs(sols)

more

Conceptually, not quite what I had in mind. But a useful command to know, regardless. EDIT: Actually, I came across a problem at GeoGebra forums where someone wanted to make a list of values of functions evaluated at a number. For 'for i in functionlist', where i became the function, i(x) gave a deprecation warning, whereas i.subs(x == evalnum) goes without warning.