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 个评论
回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!