Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculating with complex numbers
#1
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
Reply
#2
@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.
Reply
#3
Very good program, Bruno !
Why not yes ?
Reply
#4
(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.
Reply
#5
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 ???
b = b + ...
Reply
#6
"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.
Reply




Users browsing this thread: 1 Guest(s)