libdspl-2.0/dspl/src/math_poly/polyval_cmplx.c

108 wiersze
3.5 KiB
C
Czysty Zwykły widok Historia

New Structure is beginning Changes to be committed: deleted: _release/.gitignore deleted: _release/Makefile modified: _release/dspl.c modified: _release/dspl.h deleted: _release/test.c modified: dspl/Makefile modified: dspl/src/array.c new file: dspl/src/array/array_scale_lin.c new file: dspl/src/array/concat.c new file: dspl/src/array/decimate.c new file: dspl/src/array/decimate_cmplx.c new file: dspl/src/array/find_nearest.c new file: dspl/src/array/flipip.c new file: dspl/src/array/flipip_cmplx.c new file: dspl/src/array/linspace.c new file: dspl/src/array/logspace.c new file: dspl/src/array/ones.c new file: dspl/src/array/sum.c new file: dspl/src/array/sum_sqr.c modified: dspl/src/dft.c new file: dspl/src/dft/dft.c new file: dspl/src/dft/dft_cmplx.c new file: dspl/src/dft/fft.c new file: dspl/src/dft/fft_abs.c new file: dspl/src/dft/fft_abs_cmplx.c new file: dspl/src/dft/fft_cmplx.c new file: dspl/src/dft/fft_create.c new file: dspl/src/dft/fft_free.c new file: dspl/src/dft/fft_krn.c new file: dspl/src/dft/fft_mag.c new file: dspl/src/dft/fft_mag_cmplx.c new file: dspl/src/dft/fft_shift.c new file: dspl/src/dft/fft_shift_cmplx.c renamed: dspl/src/fft_subkernel.c -> dspl/src/dft/fft_subkernel.c new file: dspl/src/dft/fourier_integral_cmplx.c new file: dspl/src/dft/fourier_series_dec.c new file: dspl/src/dft/fourier_series_dec_cmplx.c new file: dspl/src/dft/fourier_series_rec.c new file: dspl/src/dft/goertzel.c renamed: dspl/src/goertzel.c -> dspl/src/dft/goertzel_cmplx.c new file: dspl/src/dft/idft_cmplx.c new file: dspl/src/dft/ifft_cmplx.c deleted: dspl/src/fft.c deleted: dspl/src/fourier_series.c new file: dspl/src/math_poly.c new file: dspl/src/math_poly/cheby_poly1.c renamed: dspl/src/cheby.c -> dspl/src/math_poly/cheby_poly2.c new file: dspl/src/math_poly/poly_z2a_cmplx.c renamed: dspl/src/polyval.c -> dspl/src/math_poly/polyroots.c new file: dspl/src/math_poly/polyval.c new file: dspl/src/math_poly/polyval_cmplx.c modified: make.inc
2021-12-29 11:33:52 +00:00
/*
* Copyright (c) 2015-2019 Sergey Bakhurin
* Digital Signal Processing Library [http://dsplib.org]
*
* This file is part of libdspl-2.0.
*
* is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DSPL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "dspl.h"
#ifdef DOXYGEN_ENGLISH
#endif
#ifdef DOXYGEN_RUSSIAN
/*! ****************************************************************************
\ingroup SPEC_MATH_POLY_GROUP
\fn int polyval_cmplx(complex_t* a, int ord, complex_t* x, int n, complex_t* y)
\brief Расчет комплексного полинома
Функция рассчитывает полином \f$P_N(x)\f$ \f$N\f$-го порядка
комплексного аргумента, заданного вектором `x`. \n
\f[
P_N(x) = a_0 + a_1 \cdot x + a_2 \cdot x^2 + a_3 \cdot x^3 + ... a_N \cdot x^N.
\f]
Для расчета используется формула Горнера: \n
\f[
P_N(x) = a_0 + x \cdot (a_1 + x \cdot (a_2 + \cdot
( \ldots x \cdot (a_{N-1} + x\cdot a_N) \ldots )))
\f]
\param[in] a
Указатель на вектор комплексных коэффициентов полинома. \n
Размер вектора `[ord+1 x 1]`. \n
Коэффициент `a[0]` соответствует коэффициенту полинома \f$a_0\f$. \n \n
\param[in] ord
Порядок полинома \f$N\f$. \n \n
\param[in] x
Указатель на вектор аргумента полинома. \n
Размер вектора `[n x 1]`. \n
Значения полинома будут расчитаны для всех значений аргумента вектора `x`. \n \n
\param[in] n
Размер вектора агрумента полинома. \n\n
\param[out] y
Указатель вектор значения полинома для аргумента `x`. \n
Размер вектора `[n x 1]`. \n
Память должна быть выделена. \n \n
\return
`RES_OK` --- полином расчитан успешно. \n
В противном случае \ref ERROR_CODE_GROUP "код ошибки".
\author Бахурин Сергей. www.dsplib.org
***************************************************************************** */
#endif
int DSPL_API polyval_cmplx(complex_t* a, int ord,
complex_t* x, int n, complex_t* y)
{
int k, m;
complex_t t;
if(!a || !x || !y)
return ERROR_PTR;
if(ord<0)
return ERROR_POLY_ORD;
if(n<1)
return ERROR_SIZE;
for(k = 0; k < n; k++)
{
RE(y[k]) = RE(a[ord]);
IM(y[k]) = IM(a[ord]);
for(m = ord-1; m>-1; m--)
{
RE(t) = CMRE(y[k], x[k]);
IM(t) = CMIM(y[k], x[k]);
RE(y[k]) = RE(t) + RE(a[m]);
IM(y[k]) = IM(t) + IM(a[m]);
}
}
return RES_OK;
}