(15C) Quadratic Equation

06292018, 12:20 PM
(This post was last modified: 06292018 01:39 PM by Gamo.)
Post: #1




(15C) Quadratic Equation
This program calculate Quadratic Equation of aX^2 + bX + c = 0
Answer can be both Real and Complex integer. Procedure: a [ENTER] b [ENTER] c f [A] > 1st Answer [X<>Y] > 2nd Answer If answer is Complex the display will show small letter (c) on screen with the Integer part shown. To see the complex part press and hold f (i) this will give you positive and negative complex answer. To disable (c) > g [CF] 8  Example 1: 2X^2 + 2X  50 = 0 2 [ENTER] 2 [ENTER] 50 [CHS] f [A] Answer: 5.5249 [X<>Y] 4.5249  Example 2: 5X^2  10X  800 = 0 5 [ENTER] 10 [CHS] [ENTER] 800 [CHS] f [A] Answer: 13.6886 [X<>Y] 11.6886  Example 3: 3x^2  2x  1 = 0 3 [CHS] [ENTER] 2 [CHS] [ENTER] 1 [CHS] f [A] Answer is Complex: 0.3333 small (c) shown on display press and hold f [ (i) ] 0.4714 Final answer is 0.3333 ± 0.4714  Program: Quadratic Equation Code:
Gamo 

07302021, 03:46 PM
(This post was last modified: 10242022 07:37 AM by C.Ret.)
Post: #2




RE: (15C) Quadratic Equation
Please let me share here an evolution of the previous code.
This new version of the solver find any roots of the Quadratic Equation of \( a.x^2 + b.x + c = 0 \) where the three coefficients \( a \) ,\( b \) and \( c \) are any real or complex numbers. Consequently, the two roots are real or complex number as well and not necessary conjugates. The usage of this new version is expressly the same as the version posted by Gamo. Code: Code: 001 2 2 012 36 ENTER Out: Y: x2 X: z1 Register: none Flags: Flag 8 is set when any root x1 or x2 is complex. Usage: Enter the three coefficients in the order \( a \), \(b\) and \(c\) where \(a\) can't be zero. Run the code by pressing the [R/S] key. You may have to add a user label at the beginning of this short code if it's sharing the program memory space with any other code. The roots of the corresponding quadratic polynomial are computed and stored in stack at X: and Y:. No memory register is used or affected by the run of this code. If one of the two roots is complex, the 'c' annunciator is lit on at the bottom of the display. it's a good practice to clear Flag_8 (complex mode indicator) before entering real coefficients, so that the appearing of the 'c' annunciator indicate that there is no real root. But this is in no way mandatory. Entering a complex number automaticaly set the flag 8 to activate the complex stack and computations. To see the complex part press and hold f[(i)]. If the complex 'c' annunciators is off and no imaginary part exist then Error 3 occurs. To see the other root press [X↔Y] key. this will give you positive and negative complex answer. Example 1 integer coefficients : \( 108x^2+1188x140616 = 0 \) Optionally, since no coefficient is a complex number, you may clear Complex Mode : g[CF][ 8 ] Enter a: [ 1 ][ 0 ][ 8 ][ENTER] Enter b: [ 1 ][ 1 ][ 8 ][ 8 ][ENTER] Enter c: [ 1 ][ 4 ][ 0 ][ 6 ][ 1 ][ 6 ][CHS] Press [R/S] to run code and display the first root: " 31.00000 " Press [X↔Y] to display the second root: "42.00000 " The roots of the quadratic equation \( 108x^2+1188x140616 = 0 \) are the two integers \(31\) and \(42\). Example 2 number coefficients : \( 5x^251.2x+131.072 = 0 \) Optionally, since no coefficient is a complex number, you may clear Complex Mode : g[CF][ 8 ] Enter a: [ 5 ][ENTER] Enter b: [ 5 ][ 1 ][ . ][ 2 ][CHS][ENTER] Enter c: [ 1 ][ 3 ][ 1 ][ . ][ 0 ][ 7 ][ 2 ] Press [R/S] to run code and display the first root: " 5.12000 " Press [X↔Y] to display the second root: " 5.12000 " (double root here !) The quadratic equation \( 5x^251.2x+131.072 = 0 \) admit a double root \( x_1=x_2=5.12 \) Example 3 integer coefficients and complex conjugate roots : \( x^24x+13 = 0 \) Optionally, since no coefficient is a complex number, you may clear Complex Mode : g[CF][ 8 ] Enter a: [ 1 ][ENTER] (entering a non zero a coefficient is mandatory) Enter b: [ 4 ][CHS][ENTER] Enter c: [ 1 ][ 3 ] Press [R/S] to run code and notice that the 'c' annunciator is displayed indicating complex roots: Real part of first root is on display " 2.00000 " Press and hold f[(i)] key to see imaginary part of first root: " 3.00000 " Press [X↔Y] to display the second root real part : " 2.00000 " Press and hold f[(i)] to display the second root’s imaginary part: "3.00000 " The two roots of quadratic equation \( z^24z+13 = 0 \) are the conjugates \(z_1=2+3i\) and \(z_2=23i=\bar{z_1}\) Example 4 full complex example : \( (2+3i).z^2+(687i).z+(483+1193i) = 0 \) Enter a: [ 2 ][ENTER] [ 3 ] f[ I ] (note that the 'c' annunciators lit on) Enter b: [ 6 ][CHS][ENTER] [ 8 ][ 7 ][CHS] f[ I ] Enter c: [ 4 ][ 8 ][ 7 ][CHS][ENTER] [ 1 ][ 1 ][ 9 ][ 3 ] f[ I ] Press [R/S] to run code. Real part of first root is " 17.00000 " Press and hold f[(i)] key to see imaginary part of first root: "7.00000 " Press [X↔Y] to display the second root real part : " 4.00000 " Press and hold f[(i)] to display the second root’s imaginary part: " 19.00000 " The two roots of quadratic equation \( (2+3i).z^2+(687i).z+(483+1193i) = 0 \) are the complex \(z_1=177i\) and \(z_2=4+19i \) Example 5 mixte example : \( (3i).z^2+(49+33i).z+12090i = 0 \) Enter a: [ 3 ][ENTER] [ 1 ][CHS] f[ I ] (note that the 'c' annunciators lit on) Enter b: [ 4 ][ 9 ][CHS][ENTER] [ 3 ][ 3 ] f[ I ] Enter c: [ 1 ][ 2 ][ 0 ][ENTER] [ 9 ][ 0 ][CHS] f[ I ] Press [R/S] to run code. Real part of first root is " 15.00000 " Press and hold f[(i)] key to see imaginary part of first root: "5.00000 " Press [X↔Y] to display the second root real part : " 3.00000 " Press and hold f[(i)] to display the second root’s imaginary part: " 0.00000 " The quadratic equation \( (3i).z^2+(49+33i).z+12090i = 0 \) have one complex root \(z_1=155i\) and one real root \(x_2=3 \) 

« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)