Re: Beginner problem with repeat
"Bill Page" <[email protected]>
| Newsgroups | gmane.comp.mathematics.axiom.user |
|---|---|
| Message-ID | <[email protected]> |
On 10/17/07, Robert Funnell <[email protected]> wrote: > Bill - > > Thanks! I'll try that tomorrow. I had read that everything but the > last thing in the loop would be thrown away, but since the solve is > the last thing in the loop, I thought I'd see its results. Why do I > need an output for the solve in the loop when I don't need it for the > one outside the loop? Contrary to what I implied in my previous email, apparently Axiom's for loop is defined to return only a "Void" result. In contrast a sequence of statements does behave as you say so that for example the value of 'x' after the execution of: x:=(1;2;3) is 3. > > Is there a simple explanation for why you need to do 'for i in plist' > then p=i rather than just 'for p in plist'? > The reason has to do with the scope of the variable inside the for-loop. It is a different 'p' then the one that you used when you defined the equation. You could write however: for p in [1000,2000,3000] repeat output solve(p^2 + 2*P + 5 = 0, 1.e-6) now with p occuring inside the loop. Alternatively you might pass p to a function that defines the equation you want to solve: eq1(p) == p^2 + 2*P + 5 = 0 for p in [1000,2000,3000] repeat output solve(eq1(p), 1.e-6) Regards, Bill Page.