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

187 wiersze
6.3 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
/*
Changes to be committed: modified: dspl/dox/doxyfile_ru modified: dspl/src/array/sum.c modified: dspl/src/filter_design/bilinear.c modified: dspl/src/filter_design/butter_ap.c modified: dspl/src/filter_design/butter_ap_zp.c modified: dspl/src/filter_design/cheby1_ap.c modified: dspl/src/filter_design/cheby1_ap_zp.c modified: dspl/src/filter_design/cheby2_ap.c modified: dspl/src/filter_design/cheby2_ap_wp1.c modified: dspl/src/filter_design/cheby2_ap_zp.c modified: dspl/src/filter_design/ellip_ap.c modified: dspl/src/filter_design/ellip_ap_zp.c modified: dspl/src/filter_design/filter_freq_resp.c modified: dspl/src/filter_design/filter_ws1.c modified: dspl/src/filter_design/filter_zp2ab.c modified: dspl/src/filter_design/fir_linphase.c modified: dspl/src/filter_design/freqs.c modified: dspl/src/filter_design/freqs2time.c modified: dspl/src/filter_design/freqs_cmplx.c modified: dspl/src/filter_design/freqz.c modified: dspl/src/filter_design/group_delay.c modified: dspl/src/filter_design/iir.c modified: dspl/src/filter_design/low2bp.c modified: dspl/src/filter_design/low2bs.c modified: dspl/src/filter_design/low2high.c modified: dspl/src/filter_design/low2low.c modified: dspl/src/filter_design/phase_delay.c modified: dspl/src/filter_design/ratcompos.c modified: dspl/src/filter_design/win.c modified: dspl/src/gnuplot/gnuplot_close.c modified: dspl/src/gnuplot/gnuplot_cmd.c modified: dspl/src/gnuplot/gnuplot_create.c modified: dspl/src/gnuplot/gnuplot_open.c modified: dspl/src/inout/dspl_info.c modified: dspl/src/inout/readbin.c modified: dspl/src/inout/verif_data_gen.c modified: dspl/src/inout/verif_str.c modified: dspl/src/inout/verif_str_cmplx.c modified: dspl/src/inout/writebin.c modified: dspl/src/inout/writetxt.c modified: dspl/src/inout/writetxt_3d.c modified: dspl/src/inout/writetxt_3dline.c modified: dspl/src/inout/writetxt_cmplx.c modified: dspl/src/inout/writetxt_cmplx_im.c modified: dspl/src/inout/writetxt_cmplx_re.c modified: dspl/src/inout/writetxt_int.c modified: dspl/src/math_ellipj/ellip_acd.c modified: dspl/src/math_ellipj/ellip_acd_cmplx.c modified: dspl/src/math_ellipj/ellip_asn.c modified: dspl/src/math_ellipj/ellip_asn_cmplx.c modified: dspl/src/math_ellipj/ellip_cd.c modified: dspl/src/math_ellipj/ellip_cd_cmplx.c modified: dspl/src/math_ellipj/ellip_landen.c modified: dspl/src/math_ellipj/ellip_modulareq.c modified: dspl/src/math_ellipj/ellip_rat.c modified: dspl/src/math_ellipj/ellip_sn.c modified: dspl/src/math_ellipj/ellip_sn_cmplx.c modified: dspl/src/math_matrix/matrix_eig_cmplx.c modified: dspl/src/math_matrix/matrix_eye.c modified: dspl/src/math_matrix/matrix_eye_cmplx.c modified: dspl/src/math_matrix/matrix_mul.c modified: dspl/src/math_matrix/matrix_pinv.c modified: dspl/src/math_matrix/matrix_print.c modified: dspl/src/math_matrix/matrix_print_cmplx.c modified: dspl/src/math_matrix/matrix_svd.c modified: dspl/src/math_matrix/matrix_transpose.c modified: dspl/src/math_matrix/matrix_transpose_cmplx.c modified: dspl/src/math_matrix/matrix_transpose_hermite.c modified: dspl/src/math_matrix/vector_dot.c modified: dspl/src/math_poly/cheby_poly1.c modified: dspl/src/math_poly/cheby_poly2.c modified: dspl/src/math_poly/polyroots.c modified: dspl/src/math_poly/polyval.c modified: dspl/src/math_poly/polyval_cmplx.c modified: dspl/src/math_stat/find_max_abs.c modified: dspl/src/math_stat/histogram.c modified: dspl/src/math_stat/histogram_norm.c modified: dspl/src/math_stat/mean.c modified: dspl/src/math_stat/mean_cmplx.c modified: dspl/src/math_stat/minmax.c modified: dspl/src/math_stat/stat_std.c modified: dspl/src/math_stat/stat_std_cmplx.c modified: dspl/src/math_stat/xcorr.c modified: dspl/src/math_std/acos_cmplx.c modified: dspl/src/math_std/asin_cmplx.c modified: dspl/src/math_std/bessel_i0.c modified: dspl/src/math_std/cos_cmplx.c modified: dspl/src/math_std/dmod.c modified: dspl/src/math_std/log_cmplx.c modified: dspl/src/math_std/sin_cmplx.c modified: dspl/src/math_std/sinc.c modified: dspl/src/math_std/sine_int.c modified: dspl/src/math_std/sqrt_cmplx.c modified: dspl/src/math_std/trapint.c modified: dspl/src/math_std/trapint_cmplx.c modified: dspl/src/math_std/unwrap.c modified: dspl/src/psd/psd_bartlett.c modified: dspl/src/psd/psd_bartlett_cmplx.c modified: dspl/src/psd/psd_periodogram.c modified: dspl/src/psd/psd_periodogram_cmplx.c modified: dspl/src/psd/psd_welch.c modified: dspl/src/psd/psd_welch_cmplx.c
2023-12-13 17:18:47 +00:00
* Copyright (c) 2015-2024 Sergey Bakhurin
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
* 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
/*! ****************************************************************************
\ingroup SPEC_MATH_POLY_GROUP
Changes to be committed: modified: dspl/dox/doxyfile_ru modified: dspl/src/array/sum.c modified: dspl/src/filter_design/bilinear.c modified: dspl/src/filter_design/butter_ap.c modified: dspl/src/filter_design/butter_ap_zp.c modified: dspl/src/filter_design/cheby1_ap.c modified: dspl/src/filter_design/cheby1_ap_zp.c modified: dspl/src/filter_design/cheby2_ap.c modified: dspl/src/filter_design/cheby2_ap_wp1.c modified: dspl/src/filter_design/cheby2_ap_zp.c modified: dspl/src/filter_design/ellip_ap.c modified: dspl/src/filter_design/ellip_ap_zp.c modified: dspl/src/filter_design/filter_freq_resp.c modified: dspl/src/filter_design/filter_ws1.c modified: dspl/src/filter_design/filter_zp2ab.c modified: dspl/src/filter_design/fir_linphase.c modified: dspl/src/filter_design/freqs.c modified: dspl/src/filter_design/freqs2time.c modified: dspl/src/filter_design/freqs_cmplx.c modified: dspl/src/filter_design/freqz.c modified: dspl/src/filter_design/group_delay.c modified: dspl/src/filter_design/iir.c modified: dspl/src/filter_design/low2bp.c modified: dspl/src/filter_design/low2bs.c modified: dspl/src/filter_design/low2high.c modified: dspl/src/filter_design/low2low.c modified: dspl/src/filter_design/phase_delay.c modified: dspl/src/filter_design/ratcompos.c modified: dspl/src/filter_design/win.c modified: dspl/src/gnuplot/gnuplot_close.c modified: dspl/src/gnuplot/gnuplot_cmd.c modified: dspl/src/gnuplot/gnuplot_create.c modified: dspl/src/gnuplot/gnuplot_open.c modified: dspl/src/inout/dspl_info.c modified: dspl/src/inout/readbin.c modified: dspl/src/inout/verif_data_gen.c modified: dspl/src/inout/verif_str.c modified: dspl/src/inout/verif_str_cmplx.c modified: dspl/src/inout/writebin.c modified: dspl/src/inout/writetxt.c modified: dspl/src/inout/writetxt_3d.c modified: dspl/src/inout/writetxt_3dline.c modified: dspl/src/inout/writetxt_cmplx.c modified: dspl/src/inout/writetxt_cmplx_im.c modified: dspl/src/inout/writetxt_cmplx_re.c modified: dspl/src/inout/writetxt_int.c modified: dspl/src/math_ellipj/ellip_acd.c modified: dspl/src/math_ellipj/ellip_acd_cmplx.c modified: dspl/src/math_ellipj/ellip_asn.c modified: dspl/src/math_ellipj/ellip_asn_cmplx.c modified: dspl/src/math_ellipj/ellip_cd.c modified: dspl/src/math_ellipj/ellip_cd_cmplx.c modified: dspl/src/math_ellipj/ellip_landen.c modified: dspl/src/math_ellipj/ellip_modulareq.c modified: dspl/src/math_ellipj/ellip_rat.c modified: dspl/src/math_ellipj/ellip_sn.c modified: dspl/src/math_ellipj/ellip_sn_cmplx.c modified: dspl/src/math_matrix/matrix_eig_cmplx.c modified: dspl/src/math_matrix/matrix_eye.c modified: dspl/src/math_matrix/matrix_eye_cmplx.c modified: dspl/src/math_matrix/matrix_mul.c modified: dspl/src/math_matrix/matrix_pinv.c modified: dspl/src/math_matrix/matrix_print.c modified: dspl/src/math_matrix/matrix_print_cmplx.c modified: dspl/src/math_matrix/matrix_svd.c modified: dspl/src/math_matrix/matrix_transpose.c modified: dspl/src/math_matrix/matrix_transpose_cmplx.c modified: dspl/src/math_matrix/matrix_transpose_hermite.c modified: dspl/src/math_matrix/vector_dot.c modified: dspl/src/math_poly/cheby_poly1.c modified: dspl/src/math_poly/cheby_poly2.c modified: dspl/src/math_poly/polyroots.c modified: dspl/src/math_poly/polyval.c modified: dspl/src/math_poly/polyval_cmplx.c modified: dspl/src/math_stat/find_max_abs.c modified: dspl/src/math_stat/histogram.c modified: dspl/src/math_stat/histogram_norm.c modified: dspl/src/math_stat/mean.c modified: dspl/src/math_stat/mean_cmplx.c modified: dspl/src/math_stat/minmax.c modified: dspl/src/math_stat/stat_std.c modified: dspl/src/math_stat/stat_std_cmplx.c modified: dspl/src/math_stat/xcorr.c modified: dspl/src/math_std/acos_cmplx.c modified: dspl/src/math_std/asin_cmplx.c modified: dspl/src/math_std/bessel_i0.c modified: dspl/src/math_std/cos_cmplx.c modified: dspl/src/math_std/dmod.c modified: dspl/src/math_std/log_cmplx.c modified: dspl/src/math_std/sin_cmplx.c modified: dspl/src/math_std/sinc.c modified: dspl/src/math_std/sine_int.c modified: dspl/src/math_std/sqrt_cmplx.c modified: dspl/src/math_std/trapint.c modified: dspl/src/math_std/trapint_cmplx.c modified: dspl/src/math_std/unwrap.c modified: dspl/src/psd/psd_bartlett.c modified: dspl/src/psd/psd_bartlett_cmplx.c modified: dspl/src/psd/psd_periodogram.c modified: dspl/src/psd/psd_periodogram_cmplx.c modified: dspl/src/psd/psd_welch.c modified: dspl/src/psd/psd_welch_cmplx.c
2023-12-13 17:18:47 +00:00
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
\brief Function calculates real polynomial roots.
Function calculates roots of the real polynomial \f$P_N(x)\f$ order \f$N\f$
with `a` coefficient vector size `[(N+1) x 1]`.
\f[
P_N(x) = a_0 + a_1 x + a_2 x^2 + a_3 x^3 + ... a_N x^N.
\f]
The roots of the polynomial are calculated as eigenvalues of the polynomial
companion matrix. To calculate the eigenvalues,
a subroutine of the LAPACK package is used.
\param[in] a
Pointer to the vector of coefficients. \n
Vector size is `[ord+1 x 1]`. \n
Coefficient `a[0]` corresponds to the \f$a_0\f$ polynomial coefficient. \n
Coefficient `a[ord]` cannot be zero. \n \n
\param[in] ord
Polynomial order \f$N\f$. \n \n
\param[out] r
Pointer to the polynomial roots vector. \n
Vector size is `[ord x 1]`. \n
Memory must be allocated. \n
The roots of a real polynomial can be either real or form simple
or multiple complex conjugate pairs of roots. Therefore, the output
root vector is of a complex data type. \n \n
\param[out] info
Pointer to the LAPACK subroutine error code. \n
This code is returned by the LAPACK subroutine and translated through
this variable for analysis.. \n\n
\return
`RES_OK` --- roots are calculated successfully. \n
Else \ref ERROR_CODE_GROUP "code error".
Example:
\include polyroots_test.c
This program calculates the roots of the polynomial
\f[
P(x) = 2 + 2x + x^2
\f]
and prints the calculated roots.
The result of the program:
\verbatim
Error code: 0x00000000
r[0] = -1.00000 1.00000 j
r[1] = -1.00000-1.00000 j
\endverbatim
\author Sergey Bakhurin. www.dsplib.org
***************************************************************************** */
#endif
#ifdef DOXYGEN_RUSSIAN
/*! ****************************************************************************
\ingroup SPEC_MATH_POLY_GROUP
Changes to be committed: modified: dspl/dox/doxyfile_ru modified: dspl/src/array/sum.c modified: dspl/src/filter_design/bilinear.c modified: dspl/src/filter_design/butter_ap.c modified: dspl/src/filter_design/butter_ap_zp.c modified: dspl/src/filter_design/cheby1_ap.c modified: dspl/src/filter_design/cheby1_ap_zp.c modified: dspl/src/filter_design/cheby2_ap.c modified: dspl/src/filter_design/cheby2_ap_wp1.c modified: dspl/src/filter_design/cheby2_ap_zp.c modified: dspl/src/filter_design/ellip_ap.c modified: dspl/src/filter_design/ellip_ap_zp.c modified: dspl/src/filter_design/filter_freq_resp.c modified: dspl/src/filter_design/filter_ws1.c modified: dspl/src/filter_design/filter_zp2ab.c modified: dspl/src/filter_design/fir_linphase.c modified: dspl/src/filter_design/freqs.c modified: dspl/src/filter_design/freqs2time.c modified: dspl/src/filter_design/freqs_cmplx.c modified: dspl/src/filter_design/freqz.c modified: dspl/src/filter_design/group_delay.c modified: dspl/src/filter_design/iir.c modified: dspl/src/filter_design/low2bp.c modified: dspl/src/filter_design/low2bs.c modified: dspl/src/filter_design/low2high.c modified: dspl/src/filter_design/low2low.c modified: dspl/src/filter_design/phase_delay.c modified: dspl/src/filter_design/ratcompos.c modified: dspl/src/filter_design/win.c modified: dspl/src/gnuplot/gnuplot_close.c modified: dspl/src/gnuplot/gnuplot_cmd.c modified: dspl/src/gnuplot/gnuplot_create.c modified: dspl/src/gnuplot/gnuplot_open.c modified: dspl/src/inout/dspl_info.c modified: dspl/src/inout/readbin.c modified: dspl/src/inout/verif_data_gen.c modified: dspl/src/inout/verif_str.c modified: dspl/src/inout/verif_str_cmplx.c modified: dspl/src/inout/writebin.c modified: dspl/src/inout/writetxt.c modified: dspl/src/inout/writetxt_3d.c modified: dspl/src/inout/writetxt_3dline.c modified: dspl/src/inout/writetxt_cmplx.c modified: dspl/src/inout/writetxt_cmplx_im.c modified: dspl/src/inout/writetxt_cmplx_re.c modified: dspl/src/inout/writetxt_int.c modified: dspl/src/math_ellipj/ellip_acd.c modified: dspl/src/math_ellipj/ellip_acd_cmplx.c modified: dspl/src/math_ellipj/ellip_asn.c modified: dspl/src/math_ellipj/ellip_asn_cmplx.c modified: dspl/src/math_ellipj/ellip_cd.c modified: dspl/src/math_ellipj/ellip_cd_cmplx.c modified: dspl/src/math_ellipj/ellip_landen.c modified: dspl/src/math_ellipj/ellip_modulareq.c modified: dspl/src/math_ellipj/ellip_rat.c modified: dspl/src/math_ellipj/ellip_sn.c modified: dspl/src/math_ellipj/ellip_sn_cmplx.c modified: dspl/src/math_matrix/matrix_eig_cmplx.c modified: dspl/src/math_matrix/matrix_eye.c modified: dspl/src/math_matrix/matrix_eye_cmplx.c modified: dspl/src/math_matrix/matrix_mul.c modified: dspl/src/math_matrix/matrix_pinv.c modified: dspl/src/math_matrix/matrix_print.c modified: dspl/src/math_matrix/matrix_print_cmplx.c modified: dspl/src/math_matrix/matrix_svd.c modified: dspl/src/math_matrix/matrix_transpose.c modified: dspl/src/math_matrix/matrix_transpose_cmplx.c modified: dspl/src/math_matrix/matrix_transpose_hermite.c modified: dspl/src/math_matrix/vector_dot.c modified: dspl/src/math_poly/cheby_poly1.c modified: dspl/src/math_poly/cheby_poly2.c modified: dspl/src/math_poly/polyroots.c modified: dspl/src/math_poly/polyval.c modified: dspl/src/math_poly/polyval_cmplx.c modified: dspl/src/math_stat/find_max_abs.c modified: dspl/src/math_stat/histogram.c modified: dspl/src/math_stat/histogram_norm.c modified: dspl/src/math_stat/mean.c modified: dspl/src/math_stat/mean_cmplx.c modified: dspl/src/math_stat/minmax.c modified: dspl/src/math_stat/stat_std.c modified: dspl/src/math_stat/stat_std_cmplx.c modified: dspl/src/math_stat/xcorr.c modified: dspl/src/math_std/acos_cmplx.c modified: dspl/src/math_std/asin_cmplx.c modified: dspl/src/math_std/bessel_i0.c modified: dspl/src/math_std/cos_cmplx.c modified: dspl/src/math_std/dmod.c modified: dspl/src/math_std/log_cmplx.c modified: dspl/src/math_std/sin_cmplx.c modified: dspl/src/math_std/sinc.c modified: dspl/src/math_std/sine_int.c modified: dspl/src/math_std/sqrt_cmplx.c modified: dspl/src/math_std/trapint.c modified: dspl/src/math_std/trapint_cmplx.c modified: dspl/src/math_std/unwrap.c modified: dspl/src/psd/psd_bartlett.c modified: dspl/src/psd/psd_bartlett_cmplx.c modified: dspl/src/psd/psd_periodogram.c modified: dspl/src/psd/psd_periodogram_cmplx.c modified: dspl/src/psd/psd_welch.c modified: dspl/src/psd/psd_welch_cmplx.c
2023-12-13 17:18:47 +00:00
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
\brief Расчет корней вещественного полинома
Функция рассчитывает корни полинома \f$P_N(x)\f$ \f$N-\f$ого
порядка, заданного вектором коэффициентов `a`.
\f[
P_N(x) = a_0 + a_1 x + a_2 x^2 + a_3 x^3 + ... a_N x^N.
\f]
Корни полинома рассчитываются как собственные числа характеристической
матрицы полинома. Для расчета собственных чисел используется подпрограмма
пакета LAPACK.
\param[in] a
Указатель на вектор вещественных коэффициентов полинома. \n
Размер вектора `[ord+1 x 1]`. \n
Коэффициент `a[0]` соответствует коэффициенту полинома \f$a_0\f$. \n
Коэффициент `a[ord]` не должен быть равен нулю. \n \n
\param[in] ord
Порядок полинома \f$N\f$. \n \n
\param[out] r
Указатель на вектор комплексных корней полинома. \n
Размер вектора `[ord x 1]`. \n
Память должна быть выделена. \n
Корни вещественного полинома могут быть как вещественными,
так и образовывать простые или кратные комплексно-сопряженные пары корней.
Поэтому выходной вектор корней имеет комплексный тип данных.
\n \n
\param[out] info
Указатель наа код возврата пакета LAPACK. \n
Данный код возвращается подпрограммой LAPACK и транслируется через данную
переменную для возможности анализа. \n\n
\return
`RES_OK` --- корни полинома рассчитаны успешно. \n
В противном случае \ref ERROR_CODE_GROUP "код ошибки".
Пример расчета корней полинома:
\include polyroots_test.c
Данная программа производит расчет корней полинома
\f[
P(x) = 2 + 2x + x^2
\f]
и выводит рассчитанные корни на печать.
Результат работы программы:
\verbatim
Error code: 0x00000000
r[0] = -1.00000 1.00000 j
r[1] = -1.00000-1.00000 j
\endverbatim
Получили пару комплексно-сопряженных корней полинома.
\author Бахурин Сергей. www.dsplib.org
***************************************************************************** */
#endif
int DSPL_API polyroots(double* a, int ord, complex_t* r, int* info)
{
complex_t *t = NULL;
int m;
int err;
if(!a || !r)
return ERROR_PTR;
if(ord<0)
return ERROR_POLY_ORD;
if(a[ord] == 0.0)
return ERROR_POLY_AN;
t = (complex_t*)malloc(ord * ord * sizeof(complex_t));
if(!t)
return ERROR_MALLOC;
for(m = 0; m < ord-1; m++)
{
RE(t[m * (ord+1) + 1]) = 1.0;
RE(t[m + ord * (ord - 1)]) = -a[m] / a[ord];
}
RE(t[ord * ord - 1]) = -a[ord-1] / a[ord];
err = matrix_eig_cmplx(t, ord, r, info);
if(t)
free(t);
return err;
}