On Fri, Aug 29, 2008 at 4:00 PM, geir.e...@gmail.com
<geir.e...@gmail.com> wrote:
> I want to construct a set of equations using strings. For example:
>
> for i in range(0,10):
> eq1="eq=x^"+str(i)+"-"+str(i)
Is there a reason why you wanted to do it using strings? It's a bit
cleaner/easier to do it without strings:
sage: eq = var('eq')
sage: eqs = [0== x^i - i for i in range(1,10)]
sage: eqs
[0 == x - 1,
0 == x^2 - 2,
0 == x^3 - 3,
0 == x^4 - 4,
0 == x^5 - 5,
0 == x^6 - 6,
0 == x^7 - 7,
0 == x^8 - 8,
0 == x^9 - 9]
But, I doubt that those are the actual equations you want. you just
need to modify the eqs = ... line to be what you need.
--Mike
Use sage_eval instead of eval, unless you want to
confusing results:
sage: eval('2/3')
0
sage: eval('2^3')
1
> ....:
> y==x**0-0
> [
> y == 1
> ]
> y==x**1-1
> [
> x == y + 1
> ]
> y==x**2-2
> [
> x == - sqrt(y + 2),
> x == sqrt(y + 2)
> ]
>
> etc...
>
> Note that double-= yields an equation (not a boolean!) if symbolic
> expressions such as x and y are involved. A single "=" is an
> assignment.
>
> Cheers
> Simon
>
> >
>
--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org