Re: Beginner problem with repeat
Robert Funnell <[email protected]>
| Newsgroups | gmane.comp.mathematics.axiom.user |
|---|---|
| Message-ID | <Pine.WNT.4.64.0710172144470.516@Earthworm> |
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?
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'?
- Robert
On Wed, 17 Oct 2007, Bill Page wrote:
> 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 <[email protected]> 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)
>>
>
--
W. Robert J. Funnell, Ph.D., Eng., Assoc. Prof.
Dept. BioMedical Engineering, McGill University
Tel. +1-514-398-6739 Fax +1-514-398-7461
[email protected] http://audilab.bmed.mcgill.ca