Mike Hansen wrote:
> Hello,
> 
> On Thu, May 28, 2009 at 8:38 AM, Paul Sargent <psa...@gmail.com> 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.


lambda is a reserved keyword in Python, which means you can't use it in 
a python statement that you are writing.  You'll notice below that Mike 
never writes lambda on a line (he only writes the string "lambda").

Yeah, I know; it's frustrating for me in linear algebra to not use 
lambda for eigenvalues.

Jason




>>
>> 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
> 
> > 
> 


-- 
Jason Grout


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

Reply via email to