[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Axiom-mail] Beginner problem with repeat
From: |
Bill Page |
Subject: |
Re: [Axiom-mail] Beginner problem with repeat |
Date: |
Wed, 17 Oct 2007 21:36:44 -0400 |
Hello Robert,
You need an output operation like this:
for ipp in 1..3 repeat
ip := ip + 1
p == plist.ip
output("p=",p)
output solve(eq1,precision)
OAxiom treats the enter for-loop as a single expression and only
outputs the value returned by the last statement executed. The rest
are thrown away unles you do something with them - like explicitly ask
for the 'output'.
Of course there are a lot of different ways to write this sort of
loop. I would probably do it something like this:
)clear all
)set message autoload off
eq1 := p^2 + 2*P + 5 = 0
precision := 1.e-6
plist := [1000,2000,3000]
for i in plist repeat
output("p=".(i::String), solve(eval(eq1,p=i),precision).1)
---------
Normally == is only used in the Axiom interpreter for defining functions.
Regards,
Bill Page.
On 10/17/07, Robert Funnell <address@hidden> wrote:
> I just started using Axiom recently and have obtained very useful
> numerical solutions of a set of equations. I am now trying to embed
> the solve in a loop so I can easily try different parameter values,
> and I can't get it to work within the loop.
>
> Appended below is a simple test. The solve within the loop is just
> silently skipped over, while the solve outside the loop gives me the
> expected result. Am I doing something silly? Or, rather, what am I
> doing that is silly?
>
> (The comment lines marked bad1 and bad2 are attempts to make the loop
> more elegant. They don't work, but that's another story.)
>
> - Robert
>
> Test case
> ---------
>
> )clear all
> )set output algebra test_results.txt
>
> eq1 == p^2 + 2*P + 5 = 0; precision := 1.e-6;
> plist == [1000,2000,3000]
>
> --bad1 for ip in 1..3 repeat
> --bad1 p == plist.ip
> --bad2 for p in plist repeat
>
> -- for some reason the solves don't get executed
> ip := 0;
> for ipp in 1..3 repeat
> ip := ip + 1;
> p == plist.ip;
> output("p=",p);
> solve(eq1,precision)
>
> -- the following solve does get executed
> output("p=",p)
> solve(eq1,precision)
>