Mathematical Fundamentals
129
line with the horizontal axis. This observation should have made the terminology
more clear.
In fig. 9 the polynomial y = f (x) = 4+3x+2x
2
-x
3
is plotted for x [-4, 4],
together with its derivative. As we can see, the derivative is positive where f (x)
is increasing, negative where f (x) is decreasing, and zero where f (x) has a local
extremal point.
-4
-2
0
2
4
-100
-50
0
50
100
y, y`
x
y(x), dy/dx
Figure 9: A degree-3 polyonomial and its derivative
The Octave/Matlab script used to produce fig. 9 is the following:
x = [-4:0.01:4];
% domain
poli = [-1 2 3 4];
% coefficients of a degree-3 polynomial
y = polyval(poli, x);
% evaluation of the polynomial
% coefficients of the derivative of the polynomial
% polid = polyderiv(poli); % Octave only
polid = poli(1:length(poli)-1).*[length(poli)-1:-1:1];
% Matlab only (polyderiv is not available)
yp = polyval(polid, x); % evaluation of the derivative
plot(x, y, '-'); hold on;
plot(x, yp, '--'); hold off;
ylabel('y, y`');
xlabel('x');
title('y(x), dy/dx');
grid;
% replot; % Octave only
In the script there are two new directives. The first one is the function invoca-
tion polyval(poli, x), which returns the vector of values taken by the polyno-
mial, whose coefficients are specified in poli, in correspondence with the points
specified in x. The second directive is the function invocation polideriv(poli),
which returns the coefficient of the polynomial that is the derivative of poli.
This function is not available in Matlab, but it can be replaced by an explicity
calculation, as indicated in the script. The fact that the derivative of a polyno-
mial is still a polynomial is ensured by the derivation rules of calculus. Namely,
the derivative of a monomial is a lower-degree monomial given by the rule
d(ax
n
)
dx
= anx
n-1
.
(34)
Next Page >>
<< Previous Page