leif wrote:
robin hankin wrote:
hello, sage 5.9
If solve() gives an unspecificed integer, how do I substitute a
particular value into the expression?
subs() does not work as expected/desired because the free variables
don't seem to be defined.
sage: a=solve(sin(x)==0,x,to_poly_solve='force');a
[x == 2*pi*z38, x == pi + 2*pi*z36]
sage: a[0].rhs()
2*pi*z38
sage: a[0].rhs().subs(z38,3)
---------------------------------------------------------------------------
NameError Traceback (most recent call
last)
<ipython-input-3-1ded925632b3> in <module>()
----> 1 a[Integer(0)].rhs().subs(z38,Integer(3))
NameError: name 'z38' is not defined
sage:
Smells like a bug...
Interestingly, still z36 is in a[0].rhs().variables().
How do I make z38 equal to 3?
Works after you manually do
sage: var('z36 z38')
(You can use .subs(z38=3) then; btw. note the equals symbol.)
Tedious, of course...
A /bit/ more automated:
sage: var(','.join([str(v) for v in a[0].variables()]))
or rather
sage: var(','.join([str(v) for v in a[0].rhs().variables()]))
P.S.: All at once:
sage: a=solve(sin(x)==0,x,to_poly_solve='force');a
[x == 2*pi*z38, x == pi + 2*pi*z36]
sage: var(','.join([str(v) for eqn in a for v in eqn.rhs().variables() ]))
(z38, z36)
-leif
To replace all occurrences, you can then e.g. also do
sage: [ eqn.subs(z38=3) for eqn in a ]
--
() The ASCII Ribbon Campaign
/\ Help Cure HTML E-Mail
--
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+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.