From ae07f87077aa07c4665ecdbbfe16b0dbd707005a Mon Sep 17 00:00:00 2001 From: Abhishek Maletha <67141747+Abhishek-photon@users.noreply.github.com> Date: Tue, 6 Oct 2020 12:37:42 +0530 Subject: [PATCH] Create shreeDharacharyaFormula.m This function calculates the roots of a quadratic equation. --- algorithms/maths/shreeDharacharyaFormula.m | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 algorithms/maths/shreeDharacharyaFormula.m diff --git a/algorithms/maths/shreeDharacharyaFormula.m b/algorithms/maths/shreeDharacharyaFormula.m new file mode 100644 index 0000000..919d28c --- /dev/null +++ b/algorithms/maths/shreeDharacharyaFormula.m @@ -0,0 +1,16 @@ +%% Shree Dharacharya Formula +% aX^2 + bX + c = 0 +function [x1,x2] = shreeDharacharyaFormula(a,b,c) + % calculates the roots of a quadratic equation. + d = b^2 - 4*a*c; + + if d < 0 + disp('Imaginary roots'); + + else + x1 = (-b + d^(1/2))/(2*a); + + x2 = (-b - d^(1/2))/(2*a); + end + +end