help-octave
[Top][All Lists]

## Error messages executing function script

 From: William Kreamer Subject: Error messages executing function script Date: Tue, 22 Jan 2002 09:29:33 -0500

```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

#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
-------------------------------------------------------------

```