Finding First non-zero derivative to find nature of turning point

6 views (last 30 days)
When given an equation, for example y= x^6 + x^5 + 2x^4 - 10x^3 + 4x^2 - 2x - 1, what code can I use that makes use of a for loop to find the first non-zero higher derivative at each turning point to determine the nature of the function?
  1 Comment
Matt J
Matt J on 24 May 2022
Edited: Matt J on 24 May 2022
For a general, non-polynomial function, note that every derivative of finite order can be zero, even at a strictly global minimum or maximum, eg., at

Sign in to comment.

Answers (1)

Jon
Jon on 24 May 2022
Edited: Jon on 24 May 2022
Assuming you are always working with polynomials you could try something like this. This code is untested but should help point you in the right direction. Should make sure that there isn't an edge case where it would get stuck in the while loop which I haven't done. Also I suspect that there is a much more elegant way to do this, but hopefully this gives you some ideas.
% paramaters
tol = 1e-10; % numerical tolerance for determining derivative is zero
% define polynomial coefficients
c = [1 1 2 -10 4 -2 -1];
% find roots of polynomial
r = roots(c);
% loop through roots obtaining first non-zero higher derivative for each
% root
numRoots = numel(r);
polyOrder = numel(c) - 1; % order of polynomial
firstNzDeriv = zeros(numRoots,1); % preallocate vector to hold results
for k = 1:numRoots
isNonZero = false;
derivOrder = 0;
cd = c;
while isNonZero
% calculate the nth derivative
derivOrder = derivOrder + 1;
cd = polyder(cd);
isNonZero = abs(polyval(cd,r(k)))>=tol;
end
firstNzDeriv(k) = derivOrder;
end

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!