help-octave
[Top][All Lists]
Advanced

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

Re: Error messages executing function script


From: William Kreamer
Subject: Re: Error messages executing function script
Date: Wed, 23 Jan 2002 09:32:02 -0500

The Octave versions I've been using are 2.0.16 when I am in Linux, and
2.1.31 when I am in Windows. The errors were appearing in both versions. I
tried to see whether there was an existing "is prime" in Octave, but didn't
find it. I'll check out Octave Forge today.
----- Original Message -----
From: "Benjamin Bunck" <address@hidden>
To: "William Kreamer" <address@hidden>
Cc: <address@hidden>
Sent: Tuesday, January 22, 2002 10:31
Subject: Re: Error messages executing function script


>
> FWIW, I tried this on 2.0.16 (I know, old!) and it worked, once
>
> Divisor += 2;
>
> was changed to:
>
> Divisor = Divisor + 2;
>
> That is to say, is_prime(29) returned 1 on the first try.  What verion of
> Octave under what OS are you using?
>
>
> Ben
>
>
> On Tue, 22 Jan 2002, William Kreamer wrote:
>
> > The script included in this email is a working function to determine
whether
> > a given number is prime. However, when I first run it, inputting a
number
> > such as 29.0, I get the error messages:
> >   can't perform indexing operation for <unknown type> type
> >   evaluating assignment expression near line 3, column 3
> >
> > When I run the script again, it works perfectly. Please help.
> >
> > #This Octave function script will take a number passed to it
> > #determine whether it is prime.
> >
> > function y = is_prime (x)
> > y = 0;
> > x = abs(x);
> > if (x < 1)
> >     Quot = 0;
> >     Leftover = 0;
> >     y = 0;
> >     return;            #exits the function
> > endif
> > x = floor(x);
> > Dividend = x;
> > Divisor = 2;
> > while(Dividend >= Divisor)
> >     Quot = floor(Dividend / Divisor);
> >     Leftover = rem(Dividend, Divisor);
> >     if (Leftover != 0)
> >          break;
> >     endif
> >     Dividend = Quot;
> > endwhile
> > Divisor = 3;
> > while(Quot >= Divisor)
> >     Quot = floor(Dividend / Divisor);
> >     Leftover = rem(Dividend, Divisor);
> >     if (Leftover == 0)
> >         Dividend = Quot;
> >         continue;
> >     endif
> >     Divisor += 2;
> > endwhile
> > if (Dividend == x)
> >     y = 1;
> > elseif (x == 2)
> >     y = 1;
> > endif
> > endfunction
> >
> >
> >
> >
> > -------------------------------------------------------------
> > Octave is freely available under the terms of the GNU GPL.
> >
> > Octave's home on the web:  http://www.octave.org
> > How to fund new projects:  http://www.octave.org/funding.html
> > Subscription information:  http://www.octave.org/archive.html
> > -------------------------------------------------------------
> >
>
>
>
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
>
> Octave's home on the web:  http://www.octave.org
> How to fund new projects:  http://www.octave.org/funding.html
> Subscription information:  http://www.octave.org/archive.html
> -------------------------------------------------------------
>
>



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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