On Thu, Feb 19, 2009 at 1:08 PM, Harald Schilly
<harald.schi...@gmail.com> wrote:
>
> In IRC I had a question and I don't know how to do it ...
>
> If you have a solution of an equation, how to apply the result to a
> function?
>
> sage: var('x y')
> (x, y)
> sage:  solve([x+y==6, x-y==4], x, y)
> [[x == 5, y == 1]]
> sage: f = 2*x+y
>
> The best I came up is
>
> sage: f.subs(dict([ (s.lhs() , s.rhs()) for s in sol[0]]))
> 11
>
> My proposal is, that Sage does this automatically, e.g. just
>
> sage: f(sol[0])
> 11
>
> Other ideas? Is this already possible?

I'd do something like this:

sage: var('x y')
(x, y)
sage: d, = solve([x+y==6, x-y==4], x, y, solution_dict=True)
sage: d
{y: 1, x: 5}
sage: f = 2*x+y
sage: f.subs(d)
11

--Mike

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to