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