Method on @sym: harmonic (x)

Symbolic harmonic function.

For integers, the harmonic function can be defined as:

syms n integer
y = harmonic (n)
  ⇒ y = (sym) harmonic(n)
rewrite (y, 'Sum')
  ⇒ (sym)

        n
       ____
       ╲
        ╲
         ╲  1
         ╱  ─
        ╱   k
       ╱
       ‾‾‾‾
      k = 1

Examples:

harmonic (sym(1:7))
  ⇒ (sym 1×7 matrix)

      ⎡              25  137  49  363⎤
      ⎢1  3/2  11/6  ──  ───  ──  ───⎥
      ⎣              12   60  20  140⎦

harmonic (sym(120))
  ⇒ ans = (sym)

      18661952910524692834612799443020757786224277983797
      ──────────────────────────────────────────────────
      3475956553913558034594585593659201286533187398464

double (ans)
  ⇒ ans = 5.3689

It is also defined for non-integers, for example:

y = harmonic (sym(1)/3)
  ⇒ y = (sym) harmonic(1/3)
vpa (y)
  ⇒ (sym) 0.44518188488072653761009301579513

y = harmonic (sym(i))
  ⇒ y = (sym) harmonic(ⅈ)
vpa (y)
  ⇒ (sym) 0.67186598552400983787839057280431 +
          1.07667404746858117413405079475⋅ⅈ

An example establishing an identity:

syms x
A = psi (x) + eulergamma ()
  ⇒ A = (sym) polygamma(0, x) + γ
rewrite (A, 'harmonic')
  ⇒ ans = (sym) harmonic(x - 1)

See also: bernoulli.

Package: symbolic