Hello,

On Thu, May 28, 2009 at 8:38 AM, Paul Sargent <[email protected]> wrote:
> # Subs for lambda (have to use "lambda", but that's a keyword)
>
> sage: e1.subs(lambda = 3)
> ------------------------------------------------------------
>   File "<ipython console>", line 1
>     e1.subs(lambda = Integer(3))
>                    ^
> SyntaxError: invalid syntax
>
> For some reason I don't understand, whilst .solve() will take the
> symbolic variable as a parameter to solve for (e.g. "t"), .subs()
> requires the variable name (e.g. "theta"). Often these are the same,
> but not always, and in the case where I have a variable "lambda" it
> causes a syntax error.
>
> Any way to get around this? Is this the intended syntax for subs(), as
> it seems a little confused?

The subs() method can take various types of input -- you can look a
the docstring to see examples of these.  Here's one way to do what you
want:

sage: l = var("lambda")
sage: t = var("theta")
sage: e1 = t == l^2
sage: e2 = e1.solve(l)
sage: (e2[0].subs({t:5}), e2[1].subs({t:5}))
(lambda == -sqrt(5), lambda == sqrt(5))
sage: sage: e1.subs({l:3})
theta == 9

In Sage 4.0, you'll be able to do

sage: sage: e1.subs(l==3)
theta == 9

--Mike

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to