Basic Calculus in Two Variables

31 views
Skip to first unread message

Pedro Cruz

unread,
Mar 30, 2015, 12:14:21 PM3/30/15
to sage-s...@googlegroups.com
In one variable

sage: x.subs(x==10) 

works ok. 

How to do a pair substitution ?

sage: var("x,y")
(x, y)
sage: (x,y).subs([x==10,y==20])
---------------------------------------------------------------------------
AttributeError: 'tuple' object has no attribute 'subs'
---------------------------------------------------------------------------

# Sage Version 6.2, Release Date: 2014-05-06                         │

William Stein

unread,
Mar 30, 2015, 12:37:11 PM3/30/15
to sage-support
On Mon, Mar 30, 2015 at 9:14 AM, Pedro Cruz <pedrocr...@gmail.com> wrote:
> In one variable
>
> sage: x.subs(x==10)
>
> works ok.
>
> How to do a pair substitution ?

var("x,y")
t = (x,y) # this is a tuple
tuple([a.subs(x=10,y=20) for a in t])
tuple([a.subs({x:10,y:20}) for a in t])
vector([x,y]).subs(x=10,y=20) # this is a vector


https://cloud.sagemath.com/projects/4a5f0542-5873-4eed-a85c-a18c706e8bcd/files/support/2015-03-30-093420-subs.sagews

>
> sage: var("x,y")
> (x, y)
> sage: (x,y).subs([x==10,y==20])
> ---------------------------------------------------------------------------
> AttributeError: 'tuple' object has no attribute 'subs'
> ---------------------------------------------------------------------------
>
> # Sage Version 6.2, Release Date: 2014-05-06 │
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-support...@googlegroups.com.
> To post to this group, send email to sage-s...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/d/optout.



--
William (http://wstein.org)

kcrisman

unread,
Mar 30, 2015, 1:42:03 PM3/30/15
to sage-s...@googlegroups.com
sage: x.subs(x==10) 

works ok. 



That's because this is a symbolic expression, "x", so you can substitute.
 
How to do a pair substitution ?

sage: var("x,y")
(x, y)
sage: (x,y).subs([x==10,y==20])


That's because (x,y) is NOT a symbolic expression, but rather a Python concept called a "tuple", which does not support this.  Are you trying to substitute into a vector?  If so,

var('y')
vector([x,y]).subs(x=10,y=20)

should work. 
Reply all
Reply to author
Forward
0 new messages