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!