How to identify the real roots of a Quadratic Equation in Excel?


Introduction

It can be difficult to work with large datasets in Microsoft Excel, especially when you must find accurate values from complex equations. Excel facilitates an excellent technique to speed up this handle and users may create a user-defined function in Visual Basic and invoke it in a specified cell. The UDF is an efficient way to resolve complex mathematical equations. In this article, we will learn how to determine the roots of the quadratic equation through a user-defined function.

Use Visual Basic Code to Evaluate the Quadratic Equation’s Root

Step 1

Open a desired worksheet and enter the following entries in the range A1:D2.

Step 2

Press ALT +F11 key to open the VBE window, move to the “Insert” tab, and then click on the “Module” option as given below −

Step 3

Write the UDF in the new module −

Function quad_roots(r1, r2, r3)
'compute the formula'
t = (r2 * r2) - (4 * r1 * r3)
Select Case t
Case 0: quad_roots = 1
Case Is > 0: quad_roots = 2
Case Else: quad_roots = 0
End Select
End Function

Save the worksheet and switch to Excel to test the generated function.

Step 4

Write the formula =quad_roots(A2,B2,C2) in the D2 cell as highlighted in below image −

Step 5

Press the “Enter” tab to evaluate the real roots of the quadratic equation. Hence, we successfully invoke and test the function in the D2 cell. The resultant value is highlighted in below image −

Conclusion

By employing these methods, we can effortlessly identify the roots of the quadratic equation in their Excel column. Within the UDF, select case expressions are defined to verify specific criteria. To obtain the desired outcome, users must call the function in the designated cell.

Updated on: 22-Dec-2023

59 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements