From b4b4fd82e0dff3de3597257e74942023a5dab92c Mon Sep 17 00:00:00 2001 From: Sergey Bakhurin Date: Fri, 2 Oct 2020 23:20:49 +0300 Subject: [PATCH] added examples for elliptic functions --- dspl/src/ellipj.c | 43 ++++++++++++++++++++++++++--- examples/src/ellip_cd_test.c | 52 ++++++++++++++++++++++++++++++++++++ examples/src/ellip_sn_test.c | 50 ++++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 examples/src/ellip_cd_test.c create mode 100644 examples/src/ellip_sn_test.c diff --git a/dspl/src/ellipj.c b/dspl/src/ellipj.c index 7c0877b..bd8ecf1 100644 --- a/dspl/src/ellipj.c +++ b/dspl/src/ellipj.c @@ -529,6 +529,15 @@ Memory must be allocated. \n \n \return `RES_OK` successful exit, else \ref ERROR_CODE_GROUP "error code". \n +Example +\include ellip_cd_test.c + +The program calculates two periods of the \f$ y = \textrm{cd}(u K(k), k)\f$ +function for different modulus values `k = 0`, `k= 0.9` и `k = 0.99`. +Also program draws the plot of calculated elliptic functions. + +\image html ellip_cd.png + \author Sergey Bakhurin www.dsplib.org ***************************************************************************** */ #endif @@ -569,9 +578,17 @@ Memory must be allocated. \n \n `RES_OK` Расчет произведен успешно. \n В противном случае \ref ERROR_CODE_GROUP "код ошибки". \n -\author -Бахурин Сергей -www.dsplib.org +Пример представлен в следующем листинге: + +\include ellip_cd_test.c + +Программа рассчитывает два периода эллиптической функции +\f$ y = \textrm{cd}(u K(k), k)\f$ для `k = 0`, `k= 0.9` и `k = 0.99`, +а также выводит графики данных функций + +\image html ellip_cd.png + +\author Бахурин Сергей www.dsplib.org ***************************************************************************** */ #endif int DSPL_API ellip_cd(double* u, int n, double k, double* y) @@ -1028,6 +1045,15 @@ Memory must be allocated. \n \n \return `RES_OK` successful exit, else \ref ERROR_CODE_GROUP "error code". \n +Example +\include ellip_sn_test.c + +The program calculates two periods of the \f$ y = \textrm{sn}(u K(k), k)\f$ +function for different modulus values `k = 0`, `k= 0.9` и `k = 0.99`. +Also program draws the plot of calculated elliptic functions. + +\image html ellip_sn.png + \author Sergey Bakhurin www.dsplib.org **************************************************************************** */ #endif @@ -1068,6 +1094,17 @@ Memory must be allocated. \n \n `RES_OK` Расчет произведен успешно. \n В противном случае \ref ERROR_CODE_GROUP "код ошибки". \n + +Пример представлен в следующем листинге: + +\include ellip_sn_test.c + +Программа рассчитывает два периода эллиптической функции +\f$ y = \textrm{sn}(u K(k), k)\f$ для `k = 0`, `k= 0.9` и `k = 0.99`, +а также выводит графики данных функций + +\image html ellip_sn.png + \author Бахурин Сергей www.dsplib.org ***************************************************************************** */ #endif diff --git a/examples/src/ellip_cd_test.c b/examples/src/ellip_cd_test.c new file mode 100644 index 0000000..de42422 --- /dev/null +++ b/examples/src/ellip_cd_test.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include "dspl.h" + + +#define N 500 + + +int main(int argc, char* argv[]) +{ + void* hdspl; /* DSPL handle */ + void* hplot; /* GNUPLOT handle */ + hdspl = dspl_load(); /* Load DSPL function */ + + double u[N]; + double y[N]; + + /* fill u*K(k) vector from -4 to 4. + We will have 2 periods sn(uK(k), k) */ + linspace(-4.0, 4.0, N, DSPL_PERIODIC, u); + + /* sn(uK(0), 0) */ + ellip_cd(u, N, 0.0, y); + writetxt(u,y,N,"dat/ellip_cd_0p00.txt"); + + /* sn(uK(0.9), 0.9) */ + ellip_cd(u, N, 0.9, y); + writetxt(u,y,N,"dat/ellip_cd_0p90.txt"); + + /* sn(uK(0.99), 0.99) */ + ellip_cd(u, N, 0.99, y); + writetxt(u,y,N,"dat/ellip_cd_0p99.txt"); + + /* plotting by GNUPLOT */ + gnuplot_create(argc, argv, 560, 360, "img/ellip_cd.png", &hplot); + gnuplot_cmd(hplot, "set grid"); + gnuplot_cmd(hplot, "set xlabel 'u'"); + gnuplot_cmd(hplot, "set ylabel 'y = cd(u, k)'"); + gnuplot_cmd(hplot, "set yrange [-1.2:1.2]"); + gnuplot_cmd(hplot, "plot 'dat/ellip_cd_0p00.txt' w l,\\"); + gnuplot_cmd(hplot, " 'dat/ellip_cd_0p90.txt' w l,\\"); + gnuplot_cmd(hplot, " 'dat/ellip_cd_0p99.txt' w l"); + gnuplot_close(hplot); + + /* free dspl handle */ + dspl_free(hdspl); + + return RES_OK; +} + + diff --git a/examples/src/ellip_sn_test.c b/examples/src/ellip_sn_test.c new file mode 100644 index 0000000..dc4aa14 --- /dev/null +++ b/examples/src/ellip_sn_test.c @@ -0,0 +1,50 @@ +#include +#include +#include +#include "dspl.h" + +#define N 500 + +int main(int argc, char* argv[]) +{ + void* hdspl; /* DSPL handle */ + void* hplot; /* GNUPLOT handle */ + hdspl = dspl_load(); /* Load DSPL function */ + + double u[N]; + double y[N]; + + /* fill u*K(k) vector from -4 to 4. + We will have 2 periods sn(uK(k), k) */ + linspace(-4.0, 4.0, N, DSPL_PERIODIC, u); + + /* sn(uK(0), 0) */ + ellip_sn(u, N, 0.0, y); + writetxt(u,y,N,"dat/ellip_sn_0p00.txt"); + + /* sn(uK(0.9), 0.9) */ + ellip_sn(u, N, 0.9, y); + writetxt(u,y,N,"dat/ellip_sn_0p90.txt"); + + /* sn(uK(0.99), 0.99) */ + ellip_sn(u, N, 0.99, y); + writetxt(u,y,N,"dat/ellip_sn_0p99.txt"); + + /* plotting by GNUPLOT */ + gnuplot_create(argc, argv, 560, 360, "img/ellip_sn.png", &hplot); + gnuplot_cmd(hplot, "set grid"); + gnuplot_cmd(hplot, "set xlabel 'u'"); + gnuplot_cmd(hplot, "set ylabel 'y = sn(u, k)'"); + gnuplot_cmd(hplot, "set yrange [-1.2:1.2]"); + gnuplot_cmd(hplot, "plot 'dat/ellip_sn_0p00.txt' w l,\\"); + gnuplot_cmd(hplot, " 'dat/ellip_sn_0p90.txt' w l,\\"); + gnuplot_cmd(hplot, " 'dat/ellip_sn_0p99.txt' w l"); + gnuplot_close(hplot); + + /* free dspl handle */ + dspl_free(hdspl); + + return RES_OK; +} + +