Polynomial Anonymous function degree
11 ビュー (過去 30 日間)
古いコメントを表示
How can I find the degree of a given "anonymous function" like f=@(x) x^2+2x; given the functions are only polynomials?
1 件のコメント
dpb
2019 年 4 月 27 日
編集済み: dpb
2019 年 4 月 27 日
Convert to string via func2str and regexp() to return powers of exponentials--find max thereof. Of course, that presumes someone doesn't write a function like using the explicit form of Horner's rule--
f=@(x) (x+2).*x;
in which case you've got more work to do... :)
採用された回答
Walter Roberson
2019 年 4 月 27 日
Build a vector
X = realmax.^(1./(1:50));
Evaluate the function at X. The first result that is finite is probably the degree. However, it is possible for a polynomial with sufficiently large coefficients to generate an infinity "early", or for with sufficiently small leading coefficient to be "late" relative to this, so you should use that as a starting point to do more cross-checking.
3 件のコメント
Walter Roberson
2019 年 4 月 28 日
x^4 is a leading coefficient of 1 which is "suffiently small" in terms of what I wrote above.
Perhaps a slightly different X would help? You should analyze why this case fails to figure out what changes to make.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Polynomials についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!