help-octave
[Top][All Lists]
Advanced

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

Re: built-in variable i


From: Johan Kullstam
Subject: Re: built-in variable i
Date: Sun, 17 Aug 2008 14:02:20 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux)

Bart Vandewoestyne <address@hidden> writes:

> Hello,
>
> I have just tested some code that I developed on Octave 2.9.12 on
> an instance of Octave 2.1.69.  I noticed difference in behavior
> due to the following apparent difference concerning the handling
> of the built in variable i:
>
> octave:19> version
> ans = 2.1.69
> octave:20> i = 2; feval(@(x) x^i, 2)
> ans = 0.76924 + 0.63896i
>
> octave:3> version
> ans = 2.9.12
> octave:4> i = 2; feval(@(x) x^i, 2)
> ans =  4
>
>
> The second form is what one would intuitively expect and is also what
> Matlab returns.

As others have pointed out, don't use the buggy old version if you can
help it.  I have many years of scripts using the old gnuplot printing
commands so I keep octave2.1 around for that.  You will have to work
around the bugs in that case.

> I often have i as the index for my for-loops, and then i often use this
> index i in my functions.  Unfortunately, it gets interpreted as sqrt(-1)
> which is not what I want.  Is there a way to prevent this in Octave 2.1.69
> (it would be nice if i could get my code running on 2.1.69 without having
> to change all the indexes in my for-loops...)  Can I maybe change the
> feval command?

I recommend to stop using "i", "j" for your index (or any) variable I
use "ii" and "jj" instead to avoid the confusion with i = sqrt(-1).
You will eventually get used to "ii" and "jj".  Plus, it is easier to
search-replace "ii" than "i" since you don't need to resort to
regexp-search-replace.


-- 
Johan KULLSTAM


reply via email to

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