QB64 Phoenix Edition
Calculating with complex numbers - Printable Version

+- QB64 Phoenix Edition (https://staging.qb64phoenix.com)
+-- Forum: Chatting and Socializing (https://staging.qb64phoenix.com/forumdisplay.php?fid=11)
+--- Forum: General Discussion (https://staging.qb64phoenix.com/forumdisplay.php?fid=2)
+--- Thread: Calculating with complex numbers (/showthread.php?tid=586)



Calculating with complex numbers - Kernelpanic - 07-05-2022

This is from the QBasic Tech Reference book, and is intended to demonstrate math with complex numbers. I myself can't see through it anymore, but anyone who deals with mathematics can perhaps use it.

Code: (Select All)
'Loesung quadratischer Gleichungen S. 231, QBasic Referenz - 5. Juli 2022

Option _Explicit

Dim a, b, c, det As Double
Dim j As String

Do
  Cls
  Print "Geben Sie die Parameter a, b, c der Gleichung ax^2 + bx + c = 0 ein: "
  Input "a = "; a: Input "b = "; b: Input "c = "; c
  Print "Loesung: ";
  If a = 0 Then
    If b = 0 Then Print "alle Zahlen" Else Print "x = "; -c / b
  Else det = b * b - 4 * a * c
    If det >= 0 Then
      Print "x1 = "; (-b + Sqr(det)) / 2 / a; "x2 = "; (-b - Sqr(det)) / 2 / a
    Else
      Print "x1 = "; b / 2 / a; "+"; Sqr(det) / 2 / a; "* i;";
      Print " x2 = "; b / 2 / a; "-"; Sqr(det) / 2 / a; "* i"
    End If
  End If
  Print
  Input "Nochmal (J/N)", j
Loop Until UCase$(j) = "N"

End



RE: Calculating with complex numbers - BSpinoza - 07-06-2022

@Kernelpanic:
Your program only solves quadratic equations with real solutions (roots).
If you try to solve a quadratic equation with complex roots, you will get an error.

example:
x^4 - 4 x +7 = 0
This equation has two complex roots:
  x_1 = 2 - sqr(3i)
  x_2 = 2 + sqr(3i)

I have attached a program, which solves the roots of a polynomial up to degree 10.
It gives in the most cases all roots of a polynomial and uses the Lin-Bairstow-Method.


RE: Calculating with complex numbers - euklides - 07-06-2022

Very good program, Bruno !


RE: Calculating with complex numbers - Kernelpanic - 07-06-2022

(07-06-2022, 07:07 AM)BSpinoza Wrote: @Kernelpanic:
Your program only solves quadratic equations with real solutions (roots).
If you try to solve a quadratic equation with complex roots, you will get an error.

example:
x^4 - 4 x +7 = 0
This equation has two complex roots:
  x_1 = 2 - sqr(3i)
  x_2 = 2 + sqr(3i)

I have attached a program, which solves the roots of a polynomial up to degree 10.
It gives in the most cases all roots of a polynomial and uses the Lin-Bairstow-Method.

Excellent program, but unfortunately I have no idea anymore of the matter. I had to first look up again what a polynomial is.

I misunderstood something in the description, one should be able to solve all quadratic equations with it.

Rechnet man nicht mit reellen , sondern mit komplexen Zahlen, ist die Wurzel von -1 als i (imaginäreZahl) definiert. Die Darstellung einer komplexen Zahl ist dann Realteil + Imaginärteil. In diesem Kalkül können alle quadratischen Gleichungen gelöst werden.



RE: Calculating with complex numbers - bplus - 07-06-2022

Yah, Solves quadratics, no calculating complex numbers except if root of the quadratic given in standard form with a, b, c as real numbers because again no complex calculation of b^2-4*a*c eg b = -i ???


RE: Calculating with complex numbers - triggered - 07-07-2022

"Yah, Solves quadratics, no calculating complex numbers except if root of the quadratic given in standard form with a, b, c as real numbers because again no complex calculation of b^2-4*a*c eg b = -i ???"

Bplus is the only guy who can slowly turn a run-on sentence into a run-on question.