function p = nextn(n) % Copyright (c) 2001-2009 by Ales Cerny %-------------------------------------------------------------------------- % nextn(n) returns a highly composite number p >= n such that the divisors % of p are in the set {2, 3, 5, 7} and 7 is present only in 1st power if at % all %-------------------------------------------------------------------------- %************************************************************************% % nextn.m - supplementary program to % % Ales Cerny (2009) Mathematical Techniques in Finance (2nd ed.) % % Princeton University Press http://press.princeton.edu/titles/9079.html % %************************************************************************% % This code is provided 'as-is', without any express or implied warranty. % % Permission is granted to anyone to use this code for any purpose, % subject to the following restrictions: % % 1. The origin of this code must not be misrepresented; you must not % claim that you wrote the original code. % 2. Modified code versions must be plainly marked as such, and must not % be misrepresented as being the original code. % 3. This notice may not be removed from any source distribution. % NOTICE TO STUDENTS: To avoid accusations of plagiarism, if you use this % code or its modifications in assessed work you should prepend it with a % note stating: % "This is the original/modified version of the code nextn.m by % Ales Cerny (2009), Mathematical Techniques in Finance (2nd ed.), % Princeton University Press. The original version is available from % http://www.martingales.info/mtfweb2". % A similar acknowledgement should appear prominently inside your written % report. flag = 1; if ((real(n)~=n) || (n < 1) ||(ceil(n)~=n)); error('the argument must be a positive integer'); elseif (n <= 10); p = n; %#ok flag=0; end p = n; while (flag == 1) p0 = p; while (mod(p0,2) == 0) p0 = p0/2; end while (mod(p0,3) == 0) p0 = p0/3; end while (mod(p0,5) == 0) p0 = p0/5; end if ((p0 == 1)||(p0==7)) flag = 0; else p=p+1; end end