vectorized roots for quadratic equations

バージョン 1.0.0 (3.17 KB) 作成者: Stephen Becker
Finds roots for a series of quadratic equations in a vectorized manner
ダウンロード 1 件
更新 2023/5/26

ライセンスの表示

Finds roots for a series of quadratic equations. This is basically the vectorized quadratic formula but with significant improvements to increase the numerical stability since the naive quadratic formula suffers from bad cancellation errors; see brief lecture notes and this helpful stack exchange post.
The benefit of using this over Matlab's builtin roots command is that this code is vectorized, so that you can give it many quadratic equations (one per row) and it solves them all, whereas with roots you need to loop over them in a for loop.
On my laptop, for solving a million quadratics, it takes about 7 seconds for Matlab's roots and about 0.1 seconds for my code.
Note: there are slight differences in convention from Matlab's roots for the cases when there is only 1 or 0 roots, since my code always needs to output 2 roots. This code will output a nan if there is a missing root, and output inf if any number is a root (that's only for the case a=b=c=0).

引用

Stephen Becker (2024). vectorized roots for quadratic equations (https://www.mathworks.com/matlabcentral/fileexchange/130109-vectorized-roots-for-quadratic-equations), MATLAB Central File Exchange. 取得済み .

MATLAB リリースの互換性
作成: R2023a
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
タグ タグを追加

Community Treasure Hunt

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

Start Hunting!
バージョン 公開済み リリース ノート
1.0.0