[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Error messages executing function script
From: |
Benjamin Bunck |
Subject: |
Re: Error messages executing function script |
Date: |
Tue, 22 Jan 2002 09:31:07 -0600 (CST) |
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
-------------------------------------------------------------