polynomial multiplication not accurate, using conv() vs symbolic

5 ビュー (過去 30 日間)
Qiang Li
Qiang Li 2024 年 5 月 31 日
コメント済み: Qiang Li 2024 年 6 月 1 日
I'm calculating the square of a polynomial inside a loop. It seems to me that, calculating it using conv() is resulting in large errors, compared to converting the polynomial to symbolic and do the calculation there.
Just out of curiosity, I tried to sym2poly the symbolic results back to polynomial, and the error appears again.
However, I can't using symbolic calculation in the loop, because it's too slow.
Any input on why this is happening and how to solve it properly? Thanks in advance.
figure
% the polynomial
D4_poly= 1.0e+06 * [ -0.000001003321333
0.000108002928093
-0.004647941272734
0.099959233380745
-1.074286120871490
4.615719487403345];
D4_fn = matlabFunction(poly2sym(D4_poly));
subplot(2,2,1);fplot(D4_fn,[19.999825010467916,23.158281544048581])
% using conv
SqD4_poly = conv(D4_poly',D4_poly');
SqD4_fn = matlabFunction(poly2sym(SqD4_poly));
subplot(2,2,2);fplot(SqD4_fn,[19.999825010467916,23.158281544048581])
% using poly2sym
temp = poly2sym(D4_poly);
SqD4_s_fn = matlabFunction(temp ^2);
subplot(2,2,3);fplot(SqD4_s_fn,[19.999825010467916,23.158281544048581])
% sym2poly
SqD4_poly_2 = sym2poly(temp ^2);
SqD4_3_fn = matlabFunction(poly2sym(SqD4_poly_2));
subplot(2,2,4);fplot(SqD4_3_fn,[19.999825010467916,23.158281544048581])

採用された回答

Matt J
Matt J 2024 年 5 月 31 日
編集済み: Matt J 2024 年 5 月 31 日
To avoid the numerical instabilities of high order polynomials, don't work with the coefficients of D4_poly^2. Just evaluate D4_poly at the desired x and square the result:
D4_poly= 1.0e+06 * [ -0.000001003321333
0.000108002928093
-0.004647941272734
0.099959233380745
-1.074286120871490
4.615719487403345];
fcn=@(x)polyval(D4_poly,x).^2;
fplot(fcn, [19.999825010467916,23.158281544048581] ); axis tight
  1 件のコメント
Qiang Li
Qiang Li 2024 年 6 月 1 日
Matt, thx for pointing out the stability issue with high order polynomials.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePolynomials についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by