How to resolve the algorithm Harmonic series step by step in the J programming language

Published on 12 May 2024 09:40 PM
#J

How to resolve the algorithm Harmonic series step by step in the J programming language

Table of Contents

Problem Statement

In mathematics, the n-th harmonic number is the sum of the reciprocals of the first n natural numbers: The series of harmonic numbers thus obtained is often loosely referred to as the harmonic series. Harmonic numbers are closely related to the Riemann zeta function, and roughly approximate the natural logarithm function; differing by γ (lowercase Gamma), the Euler–Mascheroni constant. The harmonic series is divergent, albeit quite slowly, and grows toward infinity.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Harmonic series step by step in the J programming language

Source code in the j programming language

Hn=: {{ +/ %1+i.y }}"0


   Hn i.4 5
      0       1     1.5 1.83333 2.08333
2.28333    2.45 2.59286 2.71786 2.82897
2.92897 3.01988 3.10321 3.18013 3.25156
3.31823 3.38073 3.43955 3.49511 3.54774


Hni=: {{ 0,+/\ %1+i.y}}


   4 5$Hni 20
      0       1     1.5 1.83333 2.08333
2.28333    2.45 2.59286 2.71786 2.82897
2.92897 3.01988 3.10321 3.18013 3.25156
3.31823 3.38073 3.43955 3.49511 3.54774


   Hn 1e5
12.0901


   (Hni 1e5) (] ,. I. ,. I. { [) i.13
 0     0       0
 1     1       1
 2     4 2.08333
 3    11 3.01988
 4    31 4.02725
 5    83 5.00207
 6   227 6.00437
 7   616 7.00127
 8  1674 8.00049
 9  4550 9.00021
10 12367      10
11 33617      11
12 91380      12


   (Hn 91380)-12
3.05167e_6


  

You may also check:How to resolve the algorithm Colour bars/Display step by step in the Forth programming language
You may also check:How to resolve the algorithm Pseudo-random numbers/Splitmix64 step by step in the Wren programming language
You may also check:How to resolve the algorithm Conway's Game of Life step by step in the APL programming language
You may also check:How to resolve the algorithm Perfect totient numbers step by step in the Wren programming language
You may also check:How to resolve the algorithm Arrays step by step in the CoffeeScript programming language