112 {
113
diff --git a/da/d18/quadratic__equations__complex__numbers_8cpp.html b/da/d18/quadratic__equations__complex__numbers_8cpp.html
new file mode 100644
index 000000000..9cc6c65dc
--- /dev/null
+++ b/da/d18/quadratic__equations__complex__numbers_8cpp.html
@@ -0,0 +1,359 @@
+
+
+
+
+
+
+
+
Algorithms_in_C++: math/quadratic_equations_complex_numbers.cpp File Reference
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Algorithms_in_C++ 1.0.0
+
+ Set of algorithms implemented in C++.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Loading...
+
Searching...
+
No Matches
+
+
+
+
+
+
+
+
+
Calculate quadratic equation with complex roots, i.e. b^2 - 4ac < 0.
+More...
+
#include <array>
+#include <cassert>
+#include <cmath>
+#include <complex>
+#include <exception>
+#include <iomanip>
+#include <iostream>
+
+
+namespace math
+ for IO operations
+
+
+
+
Calculate quadratic equation with complex roots, i.e. b^2 - 4ac < 0.
+
Author Renjian-buchai
+
@description Calculates any quadratic equation in form ax^2 + bx + c.
+
Quadratic equation: x = (-b +/- sqrt(b^2 - 4ac)) / 2a
+
+
+
◆ assertArray()
+
+
+
+
+
Asserts an array of complex numbers.
+
Parameters
+
+ input Input array of complex numbers. .
+ expected Expected array of complex numbers.
+ precision Precision to be asserted. Default=10
+
+
+
+
Examples /Users/runner/work/C-Plus-Plus/C-Plus-Plus/math/quadratic_equations_complex_numbers.cpp .
+
+
102 {
+
103 long double exponent =
std::pow (10, precision);
+
104 input[0].real(
std::round (input[0].real() * exponent));
+
105 input[1].real(
std::round (input[1].real() * exponent));
+
106 input[0].imag(
std::round (input[0].imag() * exponent));
+
107 input[1].imag(
std::round (input[1].imag() * exponent));
+
108
+
109 expected[0].real(
std::round (expected[0].real() * exponent));
+
110 expected[1].real(
std::round (expected[1].real() * exponent));
+
111 expected[0].imag(
std::round (expected[0].imag() * exponent));
+
112 expected[1].imag(
std::round (expected[1].imag() * exponent));
+
113
+
114 assert(input == expected);
+
115 }
+
+
+
+
+
+
+
+
+
◆ main()
+
+
+
+
+
+ int main
+ (
+ void
+ )
+
+
+
+
+
+
Main function.
+
Returns 0 on exit
+
186 {
+
+
188 return 0;
+
189 }
+
static void test()
Self-test implementations to test quadraticEquation function.
Definition: quadratic_equations_complex_numbers.cpp:122
+
+
+
+
+
+
+
◆ test()
+
+
+
+
+
+
+
+
+ static void test
+ (
+ )
+
+
+
+
+
+static
+
+
+
+
+
Self-test implementations to test quadraticEquation function.
+
Note There are 4 different types of solutions: Real and equal, real, complex, complex and equal.
+
122 {
+
123
+
+
125 "a=1 \n"
+
126 "b=-2 \n"
+
127 "c=1 \n"
+
128 "Expected output: \n"
+
129 "(1, 0), (1, 0)\n\n" ;
+
+
+
+
133
+
134
+
+
136 "a=1 \n"
+
137 "b=4 \n"
+
138 "c=5 \n"
+
139 "Expected output: \n"
+
140 "(-2, -1), (-2, 1)\n\n" ;
+
+
+
+
144
+
145
+
+
147 "a=1 \n"
+
148 "b=5 \n"
+
149 "c=1 \n"
+
150 "Expected output: \n"
+
151 "(-4.7912878475, 0), (-0.2087121525, 0)\n\n" ;
+
+
+
+
+
156
+
157
+
+
159 "a=1 \n"
+
160 "b=1 \n"
+
161 "c=1 \n"
+
162 "Expected output: \n"
+
163 "(-0.5, -0.8660254038), (-0.5, 0.8660254038)\n\n" ;
+
+
+
+
+
168
+
+
170 "Input: \n"
+
171 "a=0 \n"
+
172 "b=0 \n"
+
173 "c=0\n"
+
174 "Expected output: Exception thrown \n" ;
+
175 try {
+
+
+
178 std::cout <<
"Exception thrown successfully \n" ;
+
179 }
+
180 }
+
+
+
+
+
std::array< std::complex< long double >, 2 > quadraticEquation(long double a, long double b, long double c)
Quadratic equation calculator.
Definition: quadratic_equations_complex_numbers.cpp:53
+
void assertArray(std::array< std::complex< long double >, 2 > input, std::array< std::complex< long double >, 2 > expected, size_t precision=10)
Asserts an array of complex numbers.
Definition: quadratic_equations_complex_numbers.cpp:100
+
+
+
+
+
+
+
+
+
+
+
diff --git a/da/d18/quadratic__equations__complex__numbers_8cpp.js b/da/d18/quadratic__equations__complex__numbers_8cpp.js
new file mode 100644
index 000000000..0d3534067
--- /dev/null
+++ b/da/d18/quadratic__equations__complex__numbers_8cpp.js
@@ -0,0 +1,7 @@
+var quadratic__equations__complex__numbers_8cpp =
+[
+ [ "assertArray", "da/d18/quadratic__equations__complex__numbers_8cpp.html#af7a6d4e3dc85a6288c8f1f7094830c5a", null ],
+ [ "main", "da/d18/quadratic__equations__complex__numbers_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4", null ],
+ [ "quadraticEquation", "da/d18/quadratic__equations__complex__numbers_8cpp.html#aacb1411ef2029e81f249c21e17c96fdb", null ],
+ [ "test", "da/d18/quadratic__equations__complex__numbers_8cpp.html#aa8dca7b867074164d5f45b0f3851269d", null ]
+];
\ No newline at end of file
diff --git a/da/d18/quadratic__equations__complex__numbers_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.map b/da/d18/quadratic__equations__complex__numbers_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.map
new file mode 100644
index 000000000..f78199828
--- /dev/null
+++ b/da/d18/quadratic__equations__complex__numbers_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.map
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/da/d18/quadratic__equations__complex__numbers_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.md5 b/da/d18/quadratic__equations__complex__numbers_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.md5
new file mode 100644
index 000000000..f87c3e2cd
--- /dev/null
+++ b/da/d18/quadratic__equations__complex__numbers_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.md5
@@ -0,0 +1 @@
+9b34f7cb7af932f21f53659c0df0ff73
\ No newline at end of file
diff --git a/da/d18/quadratic__equations__complex__numbers_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg b/da/d18/quadratic__equations__complex__numbers_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg
new file mode 100644
index 000000000..b9b2ce081
--- /dev/null
+++ b/da/d18/quadratic__equations__complex__numbers_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg
@@ -0,0 +1,96 @@
+
+
+
+
+
+
+test
+
+
+Node1
+
+
+test
+
+
+
+
+
+Node2
+
+
+assertArray
+
+
+
+
+
+Node1->Node2
+
+
+
+
+
+Node5
+
+
+math::quadraticEquation
+
+
+
+
+
+Node1->Node5
+
+
+
+
+
+Node3
+
+
+std::pow
+
+
+
+
+
+Node2->Node3
+
+
+
+
+
+Node4
+
+
+std::round
+
+
+
+
+
+Node2->Node4
+
+
+
+
+
+Node6
+
+
+std::sqrt
+
+
+
+
+
+Node5->Node6
+
+
+
+
+
diff --git a/da/d18/quadratic__equations__complex__numbers_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map b/da/d18/quadratic__equations__complex__numbers_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map
new file mode 100644
index 000000000..bd1adf22b
--- /dev/null
+++ b/da/d18/quadratic__equations__complex__numbers_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
diff --git a/da/d18/quadratic__equations__complex__numbers_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 b/da/d18/quadratic__equations__complex__numbers_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5
new file mode 100644
index 000000000..077840e96
--- /dev/null
+++ b/da/d18/quadratic__equations__complex__numbers_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5
@@ -0,0 +1 @@
+da09afc8caf114a7bf5d8c4ea9d3dbd9
\ No newline at end of file
diff --git a/da/d18/quadratic__equations__complex__numbers_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg b/da/d18/quadratic__equations__complex__numbers_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg
new file mode 100644
index 000000000..76210d5c6
--- /dev/null
+++ b/da/d18/quadratic__equations__complex__numbers_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg
@@ -0,0 +1,111 @@
+
+
+
+
+
+
+main
+
+
+Node1
+
+
+main
+
+
+
+
+
+Node2
+
+
+test
+
+
+
+
+
+Node1->Node2
+
+
+
+
+
+Node3
+
+
+assertArray
+
+
+
+
+
+Node2->Node3
+
+
+
+
+
+Node6
+
+
+math::quadraticEquation
+
+
+
+
+
+Node2->Node6
+
+
+
+
+
+Node4
+
+
+std::pow
+
+
+
+
+
+Node3->Node4
+
+
+
+
+
+Node5
+
+
+std::round
+
+
+
+
+
+Node3->Node5
+
+
+
+
+
+Node7
+
+
+std::sqrt
+
+
+
+
+
+Node6->Node7
+
+
+
+
+
diff --git a/da/d18/quadratic__equations__complex__numbers_8cpp_af7a6d4e3dc85a6288c8f1f7094830c5a_cgraph.map b/da/d18/quadratic__equations__complex__numbers_8cpp_af7a6d4e3dc85a6288c8f1f7094830c5a_cgraph.map
new file mode 100644
index 000000000..8c3ac1d69
--- /dev/null
+++ b/da/d18/quadratic__equations__complex__numbers_8cpp_af7a6d4e3dc85a6288c8f1f7094830c5a_cgraph.map
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/da/d18/quadratic__equations__complex__numbers_8cpp_af7a6d4e3dc85a6288c8f1f7094830c5a_cgraph.md5 b/da/d18/quadratic__equations__complex__numbers_8cpp_af7a6d4e3dc85a6288c8f1f7094830c5a_cgraph.md5
new file mode 100644
index 000000000..5c291ae83
--- /dev/null
+++ b/da/d18/quadratic__equations__complex__numbers_8cpp_af7a6d4e3dc85a6288c8f1f7094830c5a_cgraph.md5
@@ -0,0 +1 @@
+d73edad244cdfafe5755d59e3b8c8aa3
\ No newline at end of file
diff --git a/da/d18/quadratic__equations__complex__numbers_8cpp_af7a6d4e3dc85a6288c8f1f7094830c5a_cgraph.svg b/da/d18/quadratic__equations__complex__numbers_8cpp_af7a6d4e3dc85a6288c8f1f7094830c5a_cgraph.svg
new file mode 100644
index 000000000..2b75ef982
--- /dev/null
+++ b/da/d18/quadratic__equations__complex__numbers_8cpp_af7a6d4e3dc85a6288c8f1f7094830c5a_cgraph.svg
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+assertArray
+
+
+Node1
+
+
+assertArray
+
+
+
+
+
+Node2
+
+
+std::pow
+
+
+
+
+
+Node1->Node2
+
+
+
+
+
+Node3
+
+
+std::round
+
+
+
+
+
+Node1->Node3
+
+
+
+
+
diff --git a/dd/d47/namespacemath.html b/dd/d47/namespacemath.html
index 08b4e767b..aa8b47b92 100644
--- a/dd/d47/namespacemath.html
+++ b/dd/d47/namespacemath.html
@@ -211,6 +211,9 @@ Functions
int power_of_two (int n)
This function finds whether a number is power of 2 or not.
+
std::array < std::complex < long double >, 2 > quadraticEquation (long double a, long double b, long double c)
+
Quadratic equation calculator.
+
uint64_t binomialCoeffSum (uint64_t n)
template<typename T >
@@ -1365,6 +1368,99 @@ template<typename T >
+
+
+
+
+
+
+
+
+
+
+
Loading...
+
Searching...
+
No Matches
+
+
+
+
+
+
+
+
int main() { using std::array ; using std::complex ; using std::cout ;
+
array<complex<long double, 2> solutions = quadraticEquation(1, 2, 1); cout << solutions[0] << " " << solutions[1] << "\n";
+
solutions = quadraticEquation(1, 1, 1); // Reusing solutions. cout << solutions[0] << " " << solutions[1] << "\n"; return 0; }
+
Output: (-1, 0) (-1, 0) (-0.5,0.866025) (-0.5,0.866025)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
#include <array>
+
#include <cassert>
+
#include <cmath>
+
#include <complex>
+
#include <exception>
+
#include <iomanip>
+
#include <iostream>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
long double b,
+
long double c) {
+
if (a == 0) {
+
+
}
+
+
long double discriminant = b * b - 4 * a * c;
+
+
+
if (discriminant == 0) {
+
solutions[0] = -b * 0.5 / a;
+
solutions[1] = -b * 0.5 / a;
+
return solutions;
+
}
+
+
+
+
+
+
if (discriminant > 0) {
+
+
+
+
(-b -
std::sqrt (discriminant)) * 0.5 / a, 0};
+
+
(-b +
std::sqrt (discriminant)) * 0.5 / a, 0};
+
return solutions;
+
}
+
+
+
+
-b * 0.5 / a, -
std::sqrt (-discriminant) * 0.5 / a};
+
+
-b * 0.5 / a,
std::sqrt (-discriminant) * 0.5 / a};
+
+
return solutions;
+
}
+
+
}
+
+
+
+
+
+
+
+
+
+
size_t precision = 10) {
+
long double exponent =
std::pow (10, precision);
+
input[0].real(
std::round (input[0].real() * exponent));
+
input[1].real(
std::round (input[1].real() * exponent));
+
input[0].imag(
std::round (input[0].imag() * exponent));
+
input[1].imag(
std::round (input[1].imag() * exponent));
+
+
expected[0].real(
std::round (expected[0].real() * exponent));
+
expected[1].real(
std::round (expected[1].real() * exponent));
+
expected[0].imag(
std::round (expected[0].imag() * exponent));
+
expected[1].imag(
std::round (expected[1].imag() * exponent));
+
+
assert(input == expected);
+
}
+
+
+
+
+
+
+
+
+
+
"a=1 \n"
+
"b=-2 \n"
+
"c=1 \n"
+
"Expected output: \n"
+
"(1, 0), (1, 0)\n\n" ;
+
+
+
+
+
+
+
"a=1 \n"
+
"b=4 \n"
+
"c=5 \n"
+
"Expected output: \n"
+
"(-2, -1), (-2, 1)\n\n" ;
+
+
+
+
+
+
+
"a=1 \n"
+
"b=5 \n"
+
"c=1 \n"
+
"Expected output: \n"
+
"(-4.7912878475, 0), (-0.2087121525, 0)\n\n" ;
+
+
+
+
+
+
+
+
"a=1 \n"
+
"b=1 \n"
+
"c=1 \n"
+
"Expected output: \n"
+
"(-0.5, -0.8660254038), (-0.5, 0.8660254038)\n\n" ;
+
+
+
+
+
+
+
"Input: \n"
+
"a=0 \n"
+
"b=0 \n"
+
"c=0\n"
+
"Expected output: Exception thrown \n" ;
+
try {
+
+
+
std::cout <<
"Exception thrown successfully \n" ;
+
}
+
}
+
+
+
+
+
+
+
+
return 0;
+
}
+
+
+
void test()
Definition: caesar_cipher.cpp:100
+
+
int main()
Main function.
Definition: graph_coloring.cpp:112
+
+
+
std::array< std::complex< long double >, 2 > quadraticEquation(long double a, long double b, long double c)
Quadratic equation calculator.
Definition: quadratic_equations_complex_numbers.cpp:53
+
+
void assertArray(std::array< std::complex< long double >, 2 > input, std::array< std::complex< long double >, 2 > expected, size_t precision=10)
Asserts an array of complex numbers.
Definition: quadratic_equations_complex_numbers.cpp:100
+
+
+
+
+
+
Here is a list of all examples:
diff --git a/examples.js b/examples.js
index 254788db5..45ea3fb2d 100644
--- a/examples.js
+++ b/examples.js
@@ -1,6 +1,7 @@
var examples =
[
[ "()", "db/d03/_s_t-example.html", null ],
+ [ "/Users/runner/work/C-Plus-Plus/C-Plus-Plus/math/quadratic_equations_complex_numbers.cpp", "df/dcd/_2_users_2runner_2work_2_c-_plus-_plus_2_c-_plus-_plus_2math_2quadratic_equations_complex_numbers_8cpp-example.html", null ],
[ "/Users/runner/work/C-Plus-Plus/C-Plus-Plus/numerical_methods/rungekutta.cpp", "dc/dc4/_2_users_2runner_2work_2_c-_plus-_plus_2_c-_plus-_plus_2numerical_methods_2rungekutta_8cpp-example.html", null ],
[ "/Users/runner/work/C-Plus-Plus/C-Plus-Plus/sorting/wiggle_sort.cpp", "dd/db0/_2_users_2runner_2work_2_c-_plus-_plus_2_c-_plus-_plus_2sorting_2wiggle_sort_8cpp-example.html", null ]
];
\ No newline at end of file
diff --git a/files.html b/files.html
index cb273de04..a2279e4c5 100644
--- a/files.html
+++ b/files.html
@@ -270,15 +270,16 @@ solve-a-rat-in-a-maze-c-java-pytho/" target="_blank">Rat in a Maze algorithm
prime_factorization.cpp Prime factorization of positive integers
prime_numbers.cpp Get list of prime numbers
primes_up_to_billion.cpp Compute prime numbers upto 1 billion
-
realtime_stats.cpp Compute statistics for data entered in rreal-time
-
sieve_of_eratosthenes.cpp Get list of prime numbers using Sieve of Eratosthenes
-
sqrt_double.cpp Calculate the square root of any positive real number in \(O(\log
+ quadratic_equations_complex_numbers.cpp Calculate quadratic equation with complex roots, i.e. b^2 - 4ac < 0
+
realtime_stats.cpp Compute statistics for data entered in rreal-time
+
sieve_of_eratosthenes.cpp Get list of prime numbers using Sieve of Eratosthenes
+
sqrt_double.cpp Calculate the square root of any positive real number in \(O(\log
N)\) time, with precision fixed using bisection method of root-finding
-
string_fibonacci.cpp This Programme returns the Nth fibonacci as a string
-
sum_of_binomial_coefficient.cpp Algorithm to find sum of binomial coefficients of a given positive integer
-
sum_of_digits.cpp A C++ Program to find the Sum of Digits of input integer
-
vector_cross_product.cpp Calculates the Cross Product and the magnitude of two mathematical 3D vectors
-
volume.cpp Implmentations for the volume of various 3D shapes
+
string_fibonacci.cpp This Programme returns the Nth fibonacci as a string
+
sum_of_binomial_coefficient.cpp Algorithm to find sum of binomial coefficients of a given positive integer
+
sum_of_digits.cpp A C++ Program to find the Sum of Digits of input integer
+
vector_cross_product.cpp Calculates the Cross Product and the magnitude of two mathematical 3D vectors
+
volume.cpp Implmentations for the volume of various 3D shapes
► numerical_methods
babylonian_method.cpp A babylonian method (BM) is an algorithm that computes the square root
bisection_method.cpp Solve the equation \(f(x)=0\) using bisection method
diff --git a/globals_a.html b/globals_a.html
index ab2ff2d2c..c1c8dc475 100644
--- a/globals_a.html
+++ b/globals_a.html
@@ -107,6 +107,7 @@ $(document).ready(function(){initNavTree('globals_a.html',''); initResizable();
addition_rule_independent() : addition_rule.cpp
ans() : matrix_exponentiation.cpp
are_amicable() : check_amicable_pair.cpp
+
assertArray() : quadratic_equations_complex_numbers.cpp
AvailArray : linkedlist_implentation_usingarray.cpp
diff --git a/globals_func_a.html b/globals_func_a.html
index 05710c256..38a8b049a 100644
--- a/globals_func_a.html
+++ b/globals_func_a.html
@@ -105,6 +105,7 @@ $(document).ready(function(){initNavTree('globals_func_a.html',''); initResizabl