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

4 次查看(过去 30 天)
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 个评论
Matt J
Matt J 2022-5-24
编辑:Matt J 2022-5-24
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

请先登录,再进行评论。

回答(1 个)

Jon
Jon 2022-5-24
编辑:Jon 2022-5-24
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

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by