Arduino Mohammad Bin Musa Al-Khawarazmi Solver also called Quadratic
Aduino Mohammad Bin Musa Al-Khawarazmi Solver also called Quadratic.
This programs solve read and imaginary roots of 2nd degree polynomial.
Mohammad Bin Musa Al-Khawarazmi was a Persian Mathematic from The Greate Khorasan in from 820 AC .
The Great Khorasan is currently Afghanistan, Uzbekistan, Turkmenistan, East of Iran and Tajikistan
/*
* Code MBMK-1
* Arduino Mohammad Bin Musa Al-Khawarazmi Solver also called Quadratic
* This programs solve read and imaginary roots of 2nd degree polynomial
*
* Mohammad Bin Musa Al-Khawarazmi was a Persian Mathematic from The Greate Khorasan in from 820 AC
* The Great Khorasan is currently Afghanistan, Uzbekistan, Turkmenistan, East of Iran and Tajikistan
*
* https://en.wikipedia.org/wiki/Muhammad_ibn_Musa_al-Khwarizmi
*
* written by Ahmad Shamshiri www.robojax.com, https://youTube.com/@robojax
* written on Mar 09, 2023
*
* Main idea taken from
* https://www.programiz.com/cpp-programming/examples/quadratic-roots
*/
float a=4;//value of "a"
float b=1.3;//value of "b"
float c=2;//value of "c"
float x1, x2, discriminant, realPart, imaginaryPart;
void setup() {
Serial.begin(9600);
Serial.println("================================");
Serial.println("Mohamamd Bin Musa Al-Khawarazmi 2nd Degree Solver");
discriminant = b*b - 4*a*c;
if (discriminant > 0) {
x1 = (-b + sqrt(discriminant)) / (2*a);
x2 = (-b - sqrt(discriminant)) / (2*a);
Serial.println( "Roots are real and different.");
Serial.print( "x1 = ");
Serial.println(x1);
Serial.print("x2 = ");
Serial.println(x2);
}else if(discriminant == 0){
Serial.println( "Roots are real and same.");
x1 = -b/(2*a);
Serial.print( "x1 = x2 = ");
Serial.println(x1);
}else{
realPart = -b/(2*a);
imaginaryPart =sqrt(-discriminant)/(2*a);
Serial.println("Roots are complex and different." );
Serial.print("x1 = ");
Serial.print(realPart);
Serial.print("+");
Serial.print(imaginaryPart);
Serial.println("i");
Serial.print("x2 = ");
Serial.print(realPart);
Serial.print("+");
Serial.print(imaginaryPart);
Serial.println("i");
}
}
void loop() {
// put your main code here, to run repeatedly:
}