[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: Harmonic numbers

**From**: |
Jaroslav Hajek |

**Subject**: |
Re: Harmonic numbers |

**Date**: |
Fri, 26 Feb 2010 07:15:06 +0100 |

On Thu, Feb 25, 2010 at 11:43 PM, Iliopoulos Vasileios
<address@hidden> wrote:
>* Hi All,*
>
>* I am beginner in GNU Octave. I would like to ask you how to compute*
>* in Octave the folloing expresssion*
>
>* \sum_{j=1}^{n}harmonic(j)*
>
>
>* Where harmonic(j):=\sum_{i=1}^{j}1/i*
>
>
>* Thanks*
>
You can generate the first n harmonic numbers by
h = cumsum (1 ./ (1:n));
And sum them using sum:
x = sum (h);
Or you can figure out the formula that holds for harmonic numbers:
sum (h(1:n)) = (n+1)*h(n) - n,
and use that to compute more accurately.
--
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz

**Harmonic numbers**, *Iliopoulos Vasileios*, `2010/02/25`
**Re: Harmonic numbers**,
*Jaroslav Hajek* **<=**