# polynomial multiplication not accurate, using conv() vs symbolic

7 Ansichten (letzte 30 Tage)
Qiang Li am 31 Mai 2024
Kommentiert: Qiang Li am 1 Jun. 2024
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])
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Matt J am 31 Mai 2024
Bearbeitet: Matt J am 31 Mai 2024
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 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Qiang Li am 1 Jun. 2024
Matt, thx for pointing out the stability issue with high order polynomials.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Calculus finden Sie in Help Center und File Exchange

R2023b

### Community Treasure Hunt

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

Start Hunting!

Translated by