Created
October 14, 2016 00:09
-
-
Save itsmuriuki/175f48fd61b4a415a1b52af5b52a05d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arra = [1,2,3] | |
def roots_of_eqn(coeffs) | |
a = coeffs[0] | |
b = coeffs[1] | |
c = coeffs[2] | |
d = (b * b) - (4 * a * c) | |
if d <= 0 | |
puts "Its a complex root" | |
else | |
e = Math.sqrt(d) | |
f1 = (-b + e) / (2 * a) | |
f2 = (-b - e) / (2 * a) | |
return [f1, f2] | |
end | |
end | |
puts(roots_of_eqn(arra)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment