Skip to content

Commit 73975e0

Browse files
committed
Added some new problem : Quadatric Equation Solver (L-B)
1 parent aad77be commit 73975e0

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const QuadEqnSolver = (a, b, c) => {
2+
// calculate the discriminant
3+
d = b * b - 4 * a * c;
4+
5+
// find the two solutions for x
6+
x1 = (-b + Math.sqrt(d)) / (2 * a);
7+
x2 = (-b - Math.sqrt(d)) / (2 * a);
8+
9+
// return the solution
10+
solution = { x1, x2 };
11+
return solution;
12+
};
13+
14+
console.log("🚀 ~ :", QuadEqnSolver(1, 8, 15));
15+
console.log("🚀 ~ :", QuadEqnSolver(1, 4, 4));
16+
console.log("🚀 ~ :", QuadEqnSolver(1, -7, 10));
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Quadratic Equation Solver
2+
3+
Given a Quadratic Equation
4+
$$ ax^2+bx+c=0 $$
5+
6+
We wish to find the solutions for __x__.
7+
We derive the quadratic formula from the equation above.
8+
$$ x = -b \pm \sqrt(b^2 - 4ac) / 2a $$
9+
10+
Break it down to two solutions
11+
12+
$$ x1 = -b + \sqrt(b^2 - 4ac) / 2a $$
13+
14+
$$ x1 = -b - \sqrt(b^2 - 4ac) / 2a $$
15+
16+
## Example
17+
18+
Given
19+
$$ x^2+8x+15=0 $$
20+
$$ a = 1, b = 8, c = 15 $$
21+
22+
---
23+
24+
Solution
25+
$$ x1 = -8 + \sqrt(8^2 - 4*1*15) / 2*1 $$
26+
$$ x1 = -3 $$
27+
28+
$$ x1 = -8 - \sqrt(8^2 - 4*1*15) / 2*1 $$
29+
$$ x1 = -5 $$
30+
31+
---

0 commit comments

Comments
 (0)