Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please help me write a sub procedure in Excel VBA Develop a Sub procedure to det

ID: 3677479 • Letter: P

Question

please help me write a sub procedure in Excel VBA

Develop a Sub procedure to determine the real roots of the quadratic equation ax^2 + bx + c = 0. Recall that the real roots can be determined with the quadratic formula x = -b plus or minus square root b^2 - 4ac/2a In VBA, this formula would be implemented as x1 = (-b + Sqr (b ^ 2 - 4 *a * c))/(2 * a) x2 = (-b - Sqr (b ^ 2 - 4 * a * c))/(2 * a) Test your program for the following cases: a = -1, b = 8, c = 2; and a = 1, b = 4? c = 1. in addition, try a case that yields an imaginary root: a = 7, b = 3, c = 1. What happens?

Explanation / Answer

VBA code

Imports System
Imports System.Math
              
Public Module VBModule

   Public Sub Main()
findQuadraticRoots
End Sub
  
Private Sub findQuadraticRoots()
Dim a, b, c As Integer
Dim s, x1, x2 As Double
a = -1
b = 8
c = 2
       s = Sqrt(b * b - (4 * a * c))
x1 = (-b + s) / (2 * a)
x2 = (-b - s) / (2 * a)
       MsgBox("x1=" & x1)
       MsgBox("x2=" & x2)
End Sub
  
End Module

Outputs

Input: a=-1, b=8, c=2

Output:

x1=-0.242640687119285
x2=8.24264068711928

Input: a=1, b=4, c=1

Output:

x1=-0.267949192431123
x2=-3.73205080756888

Input: a=7, b=3, c=1

Output:

x1=NaN
x2=NaN