I-th prime number

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.




ithprime(i) returns the i-th prime number.

If the argument i is a positive integer, then ithprime returns the i-th prime number. An unevaluated call is returned, if the argument is not of type Type::Numeric. An error occurs if the argument is a number that is not a positive integer.

The first prime number ithprime(1) is 2.

If the i-th prime number is contained in the system's internal prime number table (see the help page for ifactor), then it is returned by a fast kernel function. Otherwise, MuPAD® iteratively calls nextprime, using some suitable pre-computed value of ithprime as starting point. This is still reasonably fast for i ≤ 1000000. If i exceeds this value, however, then the run time grows exponentially with the number of digits of i.


Example 1

The first 10 prime numbers:

ithprime(i) $ i = 1..10

A larger prime:


Symbolic arguments lead to an unevaluated call:




An arithmetical expression



Return the number of primes in the internal prime table

ithprime(PrimeLimit) returns an integer, namely the number of primes in the internal prime number table. The table contains all primes below some bound which can be obtained by calling ifactor(PrimeLimit). On UNIX® platforms, the size of this table can be changed via the MuPAD command line flag -L.

Return Values

Prime number or an unevaluated call to ithprime

See Also

MuPAD Functions

Was this topic helpful?