I have forgotten

COST (GBP)
2.00
0.00
0

# Euler

viewed 3024 times and licensed 45 times
Calculates Euler numbers by means of recurrent relation
Controller: CodeCogs

C++

## Overview

Euler numbers, which are also called secant numbers or 'zig' numbers are defined for $\inline&space;&space;|z|&space;<\pi/2$ by
$sech(x)&space;-&space;1&space;\equiv&space;-\frac{E_1^*&space;z^2}{2!}&space;+\frac{E_2^*&space;z^4}{4!}&space;-\frac{E_3^*&space;z^6}{6!}$

The Euler number give the number of odd alternating permutations and are related to Genocchi numbers.

A slightly different convention, which is also used here, defines
$E_{2n}&space;=&space;(-1)^n&space;E_n^*$
$E_{2n+1}&space;=&space;0$

Thus, the Euler numbers $\inline&space;E_n$ and polynomials $\inline&space;E_n(x)$ are defined through equations
$sech(x)&space;=&space;\frac{2{E^z}}{{E^{2z}}+1}&space;=&space;\sum&space;_{n=0}^{\infty}{E_n}\frac{{z^n}}{n!},&space;|z|<&space;\frac{\pi&space;}{2}$
$\frac{2&space;E^{xz}&space;}{{E^z}+1}&space;=&space;\sum_{n=0}^{\infty&space;}{E_n}(x)\frac{{z^n}}{n!},&space;|z|&space;\pi$

The relation between Euler polynomials and numbers:
${E_n}&space;=&space;{2^n}{E_n}\big(\frac{1}{2}\big)$

## References:

• Higher Transcendental Functions, vol.1, (1.14) by H.Bateman and A.Erdelyi (Bateman Manuscript Project), 1953
• M.Abramowitz and I.A.Stegun, Handbook of Mathematical Functions, 1964 chapt.23

### Authors

Will Bateman (September 2005)

## EulerA

 voidEulerA( int iMax double* daEuler )
Calculates Euler numbers using the recurrent relation

${E_{2n}}&space;=&space;-\sum_{r=0}^{n-1}\big(\begin{array}{c}&space;2n&space;\\&space;2r&space;\end{array}\big){E_{2r}},&space;{e_0}=1$
${E_{2n+1}}=0,&space;n=0,1,2,...$

### Example 1

#include <stdio.h>
#include <codecogs/maths/discrete/number_theory/euler.h>

#define MAX_INDEX 16
int main()
{
double dEulerA[MAX_INDEX+1];
double dEulerB[MAX_INDEX+1];

printf( "%10s %20s %20s\n", "2n", "E_A(2n) (recurrent)", "E_B(2n) (series)" );
printf( "%8s", " " );
for( int i = 0; i < 52; i++ )
printf( "%c", '-' );
printf( "\n" );

// array calculation
Maths::NumberTheory::EulerA( MAX_INDEX, dEulerA );
Maths::NumberTheory::EulerB( MAX_INDEX, dEulerB );

// results output
for( int i = 0; i <= MAX_INDEX; i+=2 )
printf( "%10d %20.6f %20.6f\n", i, dEulerA[i], dEulerB[i]);
return 0;
}
Output:
2n  E_A(2n) (recurrent)     E_B(2n) (series)
----------------------------------------------------
0             1.000000             1.000000
2            -1.000000            -1.000000
4             5.000000             5.000000
6           -61.000000           -61.000000
8          1385.000000          1385.000000
10        -50521.000000        -50521.000000
12       2702765.000000       2702765.000000
14    -199360981.000000    -199360981.000000
16   19391512145.000000   19391512145.000027

### Parameters

 iMax input maximal index requested. Must be a power of 2. daEuler array into which to place the result, with iMax parameters.

### Returns

pointer on the resulting array of type double

### Authors

Anatoly Prognimack (Mar 19, 2005)
Developed & tested with: Borland C++ 3.1 for DOS Microsoft Visual C++ 5.0, 6.0
Updated by Will Bateman (March 2005)
##### Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.

## EulerB

 voidEulerB( int iMax double* daEuler )
Calculates Euler numbers using the recurrent series expansion

$\begin{array}{l}&space;{E_{2n}}={{(-1)}^n}2(2n)!{{\big(\frac{2}{\pi&space;}\big)}^{2n+1}}\sum&space;&space;&space;_{r=0}^{\infty&space;}\frac{{{(-1)}^r}}{{{(2r+1)}^{2n+1}}},&space;&space;\\&space;n=0,1,2,...\\&space;\end{array}$

### Parameters

 iMax input maximal index requested. Must be a power of 2. daEuler array into which to place the result, with iMax parameters.

### Returns

pointer on the resulting array of type double

### Authors

Anatoly Prognimack (Mar 19, 2005)
Developed & tested with: Borland C++ 3.1 for DOS Microsoft Visual C++ 5.0, 6.0
Will Bateman (March 2005)
##### Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.