help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: imbricated loops


From: Doug Stewart
Subject: Re: imbricated loops
Date: Fri, 5 Nov 2010 14:02:31 -0400

On Fri, Nov 5, 2010 at 1:27 PM, Delphine Fitzenz <address@hidden> wrote:
> Hi!
> It seems basic, but can-t find the reason for the bug in the FAQ or the
> manual.
> Here goes:
> EQ1, L1 and L2 are vectors of length 1000.
> when I type
>
> EQ1(1)=0;
> k=0;
> for i=2:1000
> for (j=1:i-1)
> for (k=i+1:1000)
> EQ1(i)+=L1(j)*L2(k)/(k-j);
> endfor
> endfor
>  endfor
>
> I get an error message at the 2nd for statement.
> I tried another way, with a while loop, and then I get troubles before the
> second while (the equivalent of the 3rd for) when I need to initiate k to i.
> It seems that octave does not want to evaluate the value of the counters.
> example:
>
> octave-3.2.3:46> k=0;
> octave-3.2.3:47> for i=2:1000
>> j=1;
>> while (j<i)
>> k=i;
>>
> Display all 1595 possibilities? (y or n)
> .nargin.                         invhilb
> EDITOR                           ipermute
> EQ1
>
> Thanks for any suggestion. I am used to programming in C or C++ and thought
> that just for a quick verification of a computation I could do it directly
> with octave, but it does not seem that straightforward...
> All the best,
> Delphine.
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>
>

When you use:    EQ1(i)+=

the "plus equal"   then the EQ1 array must be predefine to be 1000 long

change   EQ1(1)=0;   to be  EQ1(1000)=0;


HTH
Doug Stewart



reply via email to

[Prev in Thread] Current Thread [Next in Thread]