Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How do I assign variables from the solution of an equation?

I was pleased to see how easily Sage solves systems of equations. For example, evaluating:

var('A,B')
f(x) = A*x + B
solve([f(3) == 5, f(7) == -3], A, B)

yields:

[[A == -2, B == 11]]

With a little text editing, I can use that solution to define f, which I can then plot or use to solve other equations:

A = -2; B = 11
f(x) = A*x + B
...

Is there a way to make the assignments of A and B (or more directly, f ) from the solution of the linear equations, without the copy+paste+edit step?