bernoulli

Bernoulli numbers, and Bernoulli polynomials.

Category: Mathematics > Number Theory

Syntax

B = bernoulli(n)

Bernoulli number B_n.

B = bernoulli(n, x)

Bernoulli polynomial B_n(x).

Description

The Bernoulli numbers B_0 = 1, B_1 = -1/2, B_2 = 1/6, B_4 = -1/30, ... arise in the Euler-Maclaurin formula and in the sums of powers of integers. They are the coefficients in the series x/(exp(x) - 1) = sum(B_n*x^n/n!), and they connect to the zeta function through zeta(1 - n) = -B_n/n for n >= 2.

Pass a symbolic n such as sym(10) to get an exact fraction instead of a floating-point value.

Input arguments

n
Nonnegative integer index, scalar or array.
x
Argument of the polynomial form; usually a symbolic variable.

Output arguments

B
Bernoulli numbers as doubles, or exact rationals when n is symbolic. The odd-index numbers beyond B_1 = -1/2 are zero.

Example

Numeric and exact values

bernoulli(0:2:6)
bernoulli(sym(10))
bernoulli(sym(1))
Output
ans = 1×4

    1.0000    0.1667   -0.0333    0.0238
ans = 5/66
ans = -1/2

Notes

Use the polynomial form with caution: with a symbolic x MatLivre does not currently return the polynomial.

See also

euler zeta factorial nchoosek