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... | |
Detailed Description
Function Documentation
◆ 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 */
hdspl = dspl_load();
/* 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;
}
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: linspace.c:169
int DSPL_API writetxt(double *x, double *y, int n, char *fn)
Save real data to the text file fn. .
Definition: writetxt.c:122
int DSPL_API gnuplot_create(int argc, char *argv[], int w, int h, char *fn_png, void **hplot)
Create GNUPLOT chart.
Definition: gnuplot_create.c:202
void DSPL_API gnuplot_cmd(void *h, char *cmd)
Function sends cmd command to GNUPLOT corresponds to h handle.
Definition: gnuplot_cmd.c:82
int DSPL_API bessel_i0(double *x, int n, double *y)
Modified Bessel Function of the First Kind – [1].
Definition: bessel_i0.c:116
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 116 of file bessel_i0.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;
}
int DSPL_API sinc(double *x, int n, double a, double *y)
Function for the real vector x.
Definition: sinc.c:88
int DSPL_API sine_int(double *x, int n, double *si)
Sine integral function for the real vector x.
Definition: sine_int.c:114
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 114 of file sine_int.c.
Generated on Wed Jan 5 2022 12:44:37 for libdspl-2.0 by 1.9.2