My question is about the syntax and why does this syntax give a numerical
approximation.

To my understanding, solns is contracted from two arrays with  p,q,x,y being
the keys (because there are two solutions to the equations set). The part "for
s in solns" is putting in s ab array, and the part s[blah].n(30) asks sage
to give s[blah] in 30 bits precision.

Here is what I don't understand:

   - Is this syntax equivalent to:

for s in solns
s[q].n(30)
s[p].n(30)
s[x].n(30)
s[y].n(30)

   - Why does this method give a numerical solution.

Thanks.

On Fri, Nov 27, 2009 at 10:46 PM, John H Palmieri <jhpalmier...@gmail.com>wrote:

> On Nov 27, 10:03 am, Yotam Avital <yota...@gmail.com> wrote:
> > Hello.
> >
> > In the tutorials there is an example for numerical approximation:
> >
> > var('x y p q')
> > (x, y, p, q)
> > eq1 = p+q==9
> > eq2 = q*y+p*x==-6
> > eq3 = q*y^2+p*x^2==24
> > solns = solve([eq1,eq2,eq3,p==1],p,q,x,y, solution_dict=True)
> > [[s[p].n(30), s[q].n(30), s[x].n(30), s[y].n(30)] for s in solns]
> > [[1.0000000, 8.0000000, -4.8830369, -0.13962039],
> >  [1.0000000, 8.0000000, 3.5497035, -1.1937129]]
> >
> > As I far as I can understand, solution_dict tells sage that I want the
> > output to be in dictionary form(that is, {x:1, y:8 ...})
> > I also know that the .n(30) tell sage I want the answer to have 30
> > digits accuracy. I can't understand though the logic of the last
> > command. Can any of you explain it to me?
>
> If you're asking about the command
>
> [[s[p].n(30), s[q].n(30), s[x].n(30), s[y].n(30)] for s in solns]
>
> then note first that "solns" is a list, and a construction like [blah
> for s in solns] evaluates "blah" for each entry s in solns. If you
> just print solns at this point, you should get
>
> [{q: 8, x: -4/3*sqrt(10) - 2/3, p: 1, y: 1/6*sqrt(2)*sqrt(5) - 2/3},
>  {q: 8, x: 4/3*sqrt(10) - 2/3, p: 1, y: -1/6*sqrt(2)*sqrt(5) - 2/3}]
>
> Each entry s in solns is a dictionary with keys the variables p, q, x,
> y.  For the first entry, s[p] is 1, s[q] is 8, etc.  So the command
> that I think you were asking about prints s[p], s[q], s[x], and s[y],
> each with 30 bits of precision, for each of the two solutions.
>
> --
> John
>
> --
> 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
> URL: http://www.sagemath.org
>

-- 
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
URL: http://www.sagemath.org

Reply via email to