From help-octave-request at bevo dot che dot wisc dot edu Tue Jan 22 08:36:08 2002 Subject: Error messages executing function script From: "William Kreamer" To: 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 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 -------------------------------------------------------------