MATLAB BUILDER JA 2 Podręcznik Użytkownika Strona 51

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 292
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 50
Creating an Instance of the Class
myprimes Function
The code for myprimes is as follows:
function p = myprimes(n)
% MYPRIMES Returns the primes between 0 and n.
% P = MYPRIMES(N) Returns the primes between 0 and n.
% This file is used as an example for the MATLAB
% Builder for Java product.
% Copyright 2001-2006 The MathWorks, Inc.
if length(n) ~= 1
error('N must be a scalar');
end
if n < 2
p = zeros(1,0);
return
end
p = 1:2:n;
q = length(p);
p(1) = 2;
for k = 3:2:sqrt(n)
if p((k+1)/2)
p(((k*k+1)/2):k:q) = 0;
end
end
p = (p(p>0));
3-5
Przeglądanie stron 50
1 2 ... 46 47 48 49 50 51 52 53 54 55 56 ... 291 292

Komentarze do niniejszej Instrukcji

Brak uwag