ranges (was Numerical issues with sin()/cos() )

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

ranges (was Numerical issues with sin()/cos() )

Ian McCallion
On Wed, 28 Mar 2018, 08:34 Mike Miller, <[hidden email]> wrote:
>
> <skip>
>
> Actually it's that Octave stores ranges as a (start, step, stop)
> triplet. Let's say the value n is the range -16.5:1:16.5 as in your
> example. Octave stores that as (start=-16.5, step=1, stop=16.5).


On this point, knowing ranges were stored this way I thought recently
that the best way to code my problem was:

   for ct =1:inf
       .
       if condition; break
       .
   end

 and was disappointed it did not work. Is there a good reason it does not?

Cheers... Ian


Reply | Threaded
Open this post in threaded view
|

Re: ranges (was Numerical issues with sin()/cos() )

Francesco Potortì
>   for ct =1:inf

1:inf is not valid syntax.  Ranges need finite limits and are expanded
to an array as soon as they used, as far as I can tell.

--
Francesco Potortì (ricercatore)        Voice:  +39.050.621.3058
ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107
via G. Moruzzi 1, I-56124 Pisa         Skype:  wnlabisti
(entrance 20, 1st floor, room C71)     Web:    http://fly.isti.cnr.it



Reply | Threaded
Open this post in threaded view
|

Re: ranges (was Numerical issues with sin()/cos() )

Francesco Potortì

>>   for ct =1:inf
>
>1:inf is not valid syntax.  Ranges need finite limits and are expanded
>to an array as soon as they used, as far as I can tell.

Oh, what you want can be done like this:

while true
      if condition break;
endwhile

--
Francesco Potortì (ricercatore)        Voice:  +39.050.621.3058
ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107
via G. Moruzzi 1, I-56124 Pisa         Skype:  wnlabisti
(entrance 20, 1st floor, room C71)     Web:    http://fly.isti.cnr.it



Reply | Threaded
Open this post in threaded view
|

Re: ranges (was Numerical issues with sin()/cos() )

Ian McCallion
On Fri, 30 Mar 2018, 17:20 Francesco Potortì, <[hidden email]> wrote:

>>   for ct =1:inf
>
>1:inf is not valid syntax.  Ranges need finite limits and are expanded
>to an array as soon as they used, as far as I can tell.

Oh, what you want can be done like this:

while true
      if condition break;
endwhile

Thanks, though for equivalence I would need:

   ct=0;
   while true
       ct++;
       if condition; break
   endwhile

Which makes my version more compact familiar and readable.

The syntax of C++, java and no doubt many other languages allows use of the for loop with no end test. That Octave should join the crowd is all I was thinking.

Cheers... Ian


Reply | Threaded
Open this post in threaded view
|

Re: ranges (was Numerical issues with sin()/cos() )

Przemek Klosowski-7
On 03/30/2018 12:39 PM, Ian McCallion wrote:
Thanks, though for equivalence I would need:

   ct=0;
   while true
       ct++;
       if condition; break
   endwhile

Which makes my version more compact familiar and readable.

The syntax of C++, java and no doubt many other languages allows use of the for loop with no end test. That Octave should join the crowd is all I was thinking.

the 1:inf would not work in C++/java, and I'd argue is not very clear or readable either. If you just want to avoid end test, how about:

while ++c

  if condition break endif

endwhile

although of course  you'd have to watch for c=0