#define Real Double '+------------------------------------------------------------------------------------------+ '| Header: Bestimmen der bergabeparameter | '| AnzeigeCheck:|Il1 sind Alt-0124,Groes i,Kleines L, Eins ᎙=ܱ | Const Author="Determinante.Bas 2007 by ytwinky, MD"' | '| (Tastenkombination: keine) | '| | '| Zweck : DeterminantenBerechnung einer Matrix(z.B. vor einer Inversion) | '| Quelle: mc (mehr wei ich leider nicht mehr, sorry..) | '+------------------------------------------------------------------------------------------+ Declare Sub PrintMatrix(A() As Real) Declare Function Mpy(byVal i As Integer, byVal j As Integer, byVal k As Integer, Links() As Real, Rechts() As Real) As Real Declare Function Determinante(A() As Real) As Real Const MaxMat=10 Dim As String Menu Dim As Real A(), d, XL Dim As Integer i, j, k Dim Shared iDim As Integer Cls Print "DeterminantenBerechnung mit " &Author Print "Matrix manuell eingeben oder automatisch erzeugen (M/A)?"; Do Menu=UCase(Inkey) Sleep 1 Loop Until Instr("MA", Menu) Print Menu If Menu="A" Then Print "Eingebaute Matrix nehmen oder Zufallsmatrix (E/Z)?"; Do Menu=UCase(Inkey) Loop Until Instr("EZ", Menu) Print Menu If Menu="E" Then iDim=6 End If If Menu<>"E" Then Randomize Timer Do Print "Dimension der Matrix A (2.." &MaxMat &"):"; Input iDim Loop Until iDim>1 And iDim<=MaxMat End If iDim-=1 ReDim A(iDim, iDim) Data 0.659327444, 0.072983257, 0.979894657, 0.756750136, 0.25441669, 0.83763853 Data 0.559241606, 0.523137874, 0.948388093, 0.330784887, 0.849705537, 0.169404574 Data 0.933652887, 0.616332953, 0.217258497, 0.907022842, 0.082662047, 0.03529322 Data 0.826041544, 0.765330767, 0.52478838, 0.158009727, 0.024860119, 0.36255325 Data 0.846792095, 0.556488281, 0.48273207, 0.122986243, 0.059224104, 0.851249939 Data 0.33697323, 0.625423359, 0.494137015, 0.130947714, 0.248825667, 0.928200963 XL=0.146436546 If Menu="M" Then Print "Normales Beispiel: iDim=3, Data 1,2,3,4,5,6,7,8,8 ergibt Determinante=3" Print "Noch ein Beispiel: iDim=3, Data 1,2,3,4,5,6,7,8,9 ergibt Determinante=0" End If For i=LBound(A) To iDim 'Eingabeschleife ist Okay For j=LBound(A) To iDim Select Case Menu Case "E" Read a(i, j) Case "Z" a(i, j)=Rnd Case Else Print "a[" &(i+1) &"," &(j+1) &"]:"; Input(a(i, j)) End Select Next Next Print "Matrix ausgeben" PrintMatrix(A()) d=Determinante(A()) If Menu="E" Then ?"XL-Determinante(=Soll)=" &XL Print "Determinante=" &d; If d=0.0 Then Print ", exakt NULL" Print If Menu="E" Then Print "Differenz[Soll-Ist]=" &(XL-d) GetKey End Sub PrintMatrix(A() As Real) Dim As String MatFormat Dim As Integer i, j, vk=2, nk=6 MatFormat="+" &String$(vk, "#") &"." &String$(nk, "#") For i=LBound(A) To UBound(A) For j=LBound(A) To UBound(A) Print Using MatFormat;a(i, j); If j<>UBound(A) Then Print " "; Next Print Next End Sub Function Determinante(A() As Real) As Real Dim As Integer i, j, k, n Dim As Real LftMat(iDim, iDim), RgtMat(iDim, iDim), d=1.0 Print "Determinante berechnen" rgtmat(n, n)=d lftmat(n, n)=A(n, n) For k=n To UBound(A)-1 If lftmat(k, k)=0.0 Then Return 0.0 i=k+1 For j=n To k rgtmat(j, i)=(a(j, i)-Mpy(j-1, j, i, lftmat(), rgtmat()))/lftmat(j, j) lftmat(i, j)=a(i, j)-Mpy(j-1, i, j, lftmat(), rgtmat()) lftmat(i, i)=a(i, i)-Mpy(k, i, i, lftmat(), rgtmat()) rgtmat(i, i)=d Next Next For i=n To UBound(A) d*=lftmat(i, i) Next Function=d 'Funktionsergebnis an den Namen zuweisen!!! Erase LftMat, RgtMat End Function Function Mpy(byVal i As Integer, byVal j As Integer, byVal k As Integer, LftMat() As Real, RgtMat() As Real) As Real 'Funktioniert nur mit Determinante ZUSAMMEN.. Dim m As Integer, d As Real For m=LBound(LftMat) To i d+=lftmat(j, m)*rgtmat(m, k) Next Return d End Function