libdspl-2.0 Digital Signal Processing Algorithm Library
Transcendent math functions

## Functions

int DSPL_API bessel_i0 (double *x, int n, double *y)
Modified Bessel Function of the First Kind – $$I_0(x)$$ [1]. More...

int DSPL_API sine_int (double *x, int n, double *si)
Sine integral function $$\textrm{Si}(x)$$ for the real vector x. More...

## ◆ bessel_i0()

 int bessel_i0 ( double * x, int n, double * y )

Modified Bessel Function of the First Kind – $$I_0(x)$$ [1].

Parameters
 [in] x Pointer to the function argument vector $$x$$. Vector size is [n x 1]. Input vector must contain nonnegative values. [in] n Input vector size x. [out] y Pointer to $$I_0(x)$$ function vector. Vector size is [n x 1]. Memory must be allocated.
Returns
RES_OK if function calculated successfully.
Else code error.
Note
[1] Rational Approximations for the Modified Bessel Function of the First Kind – I0(x) for Computations with Double Precision by PAVEL HOLOBORODKO on NOVEMBER 11, 2015

Example:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dspl.h"
#define N 50
/******************************************************************************
* Main function
******************************************************************************/
int main(int argc, char* argv[])
{
void* hdspl; /* DSPL handle */
void* hplot; /* GNUPLOT handle */
double x[N], y[N];
/* Load DSPL function */
/* x in [0, 3] */
linspace(0.0, 3.0, N, DSPL_SYMMETRIC, x);
/* Bessel I0(x) function */
bessel_i0(x, N, y);
/* Write calculated values to the dat/dat0.txt file */
writetxt(x, y, N, "dat/dat0.txt");
/* plotting by GNUPLOT */
gnuplot_create(argc, argv, 560, 380, "img/bessel_i0.png", &hplot);
gnuplot_cmd(hplot, "set grid");
gnuplot_cmd(hplot, "set xlabel 'x'");
gnuplot_cmd(hplot, "set key left top");
gnuplot_cmd(hplot, "set ylabel 'I_0(x)'");
gnuplot_cmd(hplot, "set yrange [0:5]");
gnuplot_cmd(hplot, "plot 'dat/dat0.txt' with lines");
gnuplot_close(hplot);
/* free dspl handle */
dspl_free(hdspl);
return 0;
}

Program calcultes $$I_0(x)$$ function for x in $$[0 \ 3]$$ interval. Data saved if dat/dat0.txt file and shows on the plot

Definition at line 386 of file math.c.

## ◆ sine_int()

 int sine_int ( double * x, int n, double * si )

Sine integral function $$\textrm{Si}(x)$$ for the real vector x.

$\textrm{Si}(x) = \int_{0}^{x} \frac{\sin(x)}{x} \, dx$

This function uses Padé approximants of the convergent Taylor series.

Parameters
 [in] x Pointer to the input vector $$x$$. Vector size is [n x 1]. Memory must be allocated. [in] n Size of input vector x. [out] si Pointer to the Si function vector. Vector size is [n x 1]. Memory must be allocated.
Returns
RES_OK if function calculated successfully.
Else code error.
Example:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dspl.h"
#define N 400
int main(int argc, char* argv[])
{
void* hdspl; /* DSPL handle */
void* hplot; /* GNUPLOT handle */
hdspl = dspl_load(); /* Load DSPL function */
double x[N], y[N];
linspace(-6*M_PI, 6*M_PI, N, DSPL_PERIODIC, x);
sine_int(x, N, y);
writetxt(x, y, N, "dat/dat0.txt");
sinc(x, N, 1.0, y);
writetxt(x, y, N, "dat/dat1.txt");
/* plotting by GNUPLOT */
gnuplot_create(argc, argv, 560, 280, "img/sine_int.png", &hplot);
gnuplot_cmd(hplot, "set grid");
gnuplot_cmd(hplot, "set xlabel 'x'");
gnuplot_cmd(hplot, "set lmargin at screen 0.10");
gnuplot_cmd(hplot, "set key left top");
gnuplot_cmd(hplot, "set ylabel 'Si(x), sinc(x)'");
gnuplot_cmd(hplot, "set yrange [-2:2]");
gnuplot_cmd(hplot, "plot 'dat/dat0.txt' with lines title 'Si(x)', \\");
gnuplot_cmd(hplot, " 'dat/dat1.txt' with lines title 'sinc(x)'");
gnuplot_close(hplot);
dspl_free(hdspl); // free dspl handle
return 0;
}

This program calcultes sine integral $$\textrm{Si}(x)$$ and $$\textrm{sinc}(x)$$ functions for input x vector in interval $$[-6\pi \ 6\pi]$$. Functions values saved to th
dat/dat0.txt and dat/dat1.txt files and showed on the figure:

Definition at line 1043 of file math.c.

int DSPL_API sine_int(double *x, int n, double *si)
Sine integral function for the real vector x.
Definition: math.c:1043
void DSPL_API gnuplot_close(void *h)
Close GNUPLOT handle.
Definition: gnuplot.c:325
Perform dynamic linking and load libdspl-2.0 functions.
void DSPL_API gnuplot_cmd(void *h, char *cmd)
Function sends cmd command to GNUPLOT corresponds to h handle.
Definition: gnuplot.c:390
int DSPL_API writetxt(double *x, double *y, int n, char *fn)
Save real data to the text file fn. .
Definition: inout.c:491
void dspl_free(void *handle)
Cleans up the previously linked DSPL-2.0 dynamic library.
int DSPL_API linspace(double x0, double x1, int n, int type, double *x)
Function fills a vector with n linearly spaced elements between x0 and x1.
Definition: array.c:1041
int DSPL_API bessel_i0(double *x, int n, double *y)
Modified Bessel Function of the First Kind – [1].
Definition: math.c:386
int DSPL_API sinc(double *x, int n, double a, double *y)
Function for the real vector x.
Definition: math.c:936
int DSPL_API gnuplot_create(int argc, char *argv[], int w, int h, char *fn_png, void **hplot)
Create GNUPLOT chart.
Definition: gnuplot.c:200