suppose that there is given following matlab code
function dp = derp(p)
n = length(p) - 1;
p = p(:)';
dp = p(1:n).*(n:-1:1);
k = find(dp ~= 0);
if ~isempty(k)
dp = dp(k(1):end);
else
dp = 0;
end
as i know from the book,from where i have taken this code,it is explained just that it calculates derivative of function,of polynomials,but in case of i would like to write it in c++,how to rewrite it?please explain me ideas of this code,i just need to fully understand even in matlab what does it do,for a few moment let’s forget c++ and pay attention to main ideas of code,please guys help me,i know actualy ,mathematicaly how derivative is calculated,i need understanding in code
The polynomial is represented as a list of coeficients.
make sure p is a row vector.
multiply each element by it’s index
remove any zero items from the front of the list
in C you would write it probably like this:
Where the caller is responsible for allocating an array of size
polysize-1for dervpoly.The polynomial is:
Note that it may be more convenient to store the coefficients in reverse order.