Graphics Programs Reference
In-Depth Information
Forapolynomialofdegree n , the procedurecan besummarizedas
P 0 ( x )
=
a 1
P i ( x )
=
a n + i +
xP i 1 ( x ),
i
=
1
,
2
,...,
n
(4.10)
leading to the algorithm
p = a(1);
fori=1:n
p=p*x+a(i+1)
end
The last algorithm involves only n multiplications, making it moreefficientfor
n
Butcomputational economy is not the prime reasonwhy this algorithm should
be used. Because the result of each multiplicationis rounded off, the procedure with
the least number of multiplications invariablyaccumulates the smallest roundoff
error.
Some root-finding algorithms, including Laguerre's method, also requireeval-
uation of the first and second derivatives of P n ( x )
>
3
.
.
FromEq. (4.10) weobtain by
differentiation
P 0 ( x )
0 P i ( x )
xP
i
=
=
P i 1 ( x )
+
1 ( x ),
i
=
1
,
2
,...,
n
(4.11a)
P
0
0 P
i
2 P
i
xP
i
( x )
=
( x )
=
1 ( x )
+
1 ( x ),
i
=
1
,
2
,...,
n
(4.11b)
evalPoly
Here is the function thatevaluates apolynomial and its derivatives:
function [p,dp,ddp] = evalpoly(a,x)
% Evaluates the polynomial
%p=a(1)*xˆn+a(2)*xˆ(n-1)+...+a(n+1)
% and its first two derivatives dp and ddp.
% USAGE: [p,dp,ddp] = evalpoly(a,x)
n = length(a) - 1;
p=a(1);dp=0.0;ddp=0.0;
fori=1:n
ddp = ddp*x + 2.0*dp;
dp=dp*x+p;
p=p*x+a(i+1);
end
Search WWH ::




Custom Search