| |
|
|
p.specht
| En verschiedenen Optimierungsaufgaben (etwa en el Regelungstechnik) es manchmal notwendig, a siempre neuen Ergebnisvektoren (Zielvorgaben) el entsprechenden Lösungen el Variables (z.B. Ventilstellungen) para encontrar, während el sonstigen maschinellen Gegebenheiten (abgebildet en uno Matrix) siempre igual bleiben. Ein Verfahren, el no jedesmal una komplette Matrizeninversion erfordert, podría esta Tarea deutlich beschleunigen. El sog. L U - Zerlegung es una solches Verfahren.
Sie dient en el übrigen auch como Standard-Benchmark a Beurteilung el Rechenleistung de Supercomputern (siehe TOP 500-Liste) - freilich no en el nachstehenden schnarchlangsamen Variante, el sólo el Principio verdeutlichen se.
Windowtitle "LU-Faktorisierung con Zeilentausch, para mehrfache LGS-Lösung"
Font 2:randomize:CLS rnd(8^8)
AppendMenuBar 10,"Obere Dreiecksmatrix via Grundstruktur, anschl. son mehrfach Lösungen por Vektor-Rücktausch möglich"
'{ (D) Demoware 2012-06-01 P. Pájaro carpintero, Wien por Übersetzung de HP-Basic.
' Ohne jedwede Gewähr! Nutzung en propio Risiko des Anwenders!
' El Originalvorlage hatte folgende Rechtshinweise:
' Copyright 1987
' John H. Mathews
' Dept. of Mathematics
' California State University, Fullerton
' LU Factorization with Row Interchanges
'} PROGRAM LU FACTOR AND SOLVE
'{ ' MAIN PART
Declarar A![10,10], A1![10,10], B![10], ROW&[10], X![10]
Declarar n&,i&,j&,k&,inrc!,ans$,row&,col&,ach$,tmp$,det!
Declarar p&,rowk&,rowp&,c&,t&,sum!
g110:
p300' call SUBROUTINE INPUTS
p1000' call SUBROUTINE FACTOR
g125:
Imprimir "\nENTER THE COLUMN VECTOR B:"
p900' call SUBROUTINE VECTOR INPUT
caso DET!<>0:p1500' call SUBROUTINE SOLVE
p3000' call SUBROUTINE RESULTS
If DET!<>0
Imprimir " WANT TO SOLVE A*X=B WITH A NEW VECTOR B ? <Y/N> ";
Entrada ANS$
Case (ANS$="Y") Or (ANS$="y") Or (ANS$="j") Or (ANS$="J") : Goto "g125"
EndIf
Imprimir " WANT TO SOLVE ANOTHER LINEAR SYSTEM ? <Y/N> ";
Entrada ANS$:Case (ANS$="Y") Or (ANS$="y") Or (ANS$="J") Or (ANS$="j"):Goto "g110"
End
'}
Proc p300' INPUT CONTROL
CLS rnd(8^8)
Imprimir "\n SOLUTION OF A LINEAR SYSTEM A[ , ] * X[ ] = B[ ] "
Imprimir
Imprimir " THE TRIANGULAR FACTORIZATION L * U = P * A IS CONSTRUCTED."
Imprimir " FIRST, THE SOLUTION Y TO L * Y = P * B IS FOUND,"
Imprimir " SECOND, THE SOLUTION X TO U * X = Y IS FOUND."
Imprimir
Imprimir " A[ , ] IS AN N BY N NONSINGULAR MATRIX."
Imprimir " B[ ] IS AN N DIMENSIONAL VECTOR OF CONSTANTS."
Imprimir " X[ ] IS THE N DIMENSIONAL SOLUTION VECTOR OF A*X=B"
Imprimir
Imprimir " ENTER NUMBER OF EQUATIONS: N = ";
Entrada N&
INRC!=0
Imprimir " DO YOU WANT TO INPUT PER COLUMN? (Y=COLUMNS, N=ROWS) <Y/N> ";
Entrada ANS$
Case (ANS$="Y") Or (ANS$="y") Or (ANS$="J") Or (ANS$="j") : INRC!=1
Imprimir
Imprimir " ENTER THE MATRIX A(I,J) TO BE TRIANGLED:"
p600' call SUBROUTINE MATRIX INPUT
Volver
ENDPROC
Proc p600' SUBROUTINE MATRIX INPUT
WhileLoop n&:row&=&Loop
WhileLoop n&:col&=&Loop
A![ROW&,COL&]=0
EndWhile
EndWhile
'Imprimir " ELEMENTS OF THE MATRIX "
If INRC!=0
Goto "g690"
Más
Goto "g780"
EndIf
g690:
WhileLoop n&:row&=&Loop
Imprimir "\n INPUT THE ELEMENTS OF ROW ",ROW&
Imprimir
WhileLoop n&:col&=&Loop
Imprimir "A(";ROW&;",";COL&;") = ";
Entrada A![ROW&,COL&]
A1![ROW&,COL&] = A![ROW&,COL&]
EndWhile
EndWhile
Goto "g870"
g780:
WhileLoop n&:col&=&Loop
Imprimir "\n INPUT THE ELEMENTS OF COLUMN ",COL&
Imprimir
WhileLoop n&:row&=&Loop
Imprimir " A(";ROW&;",";COL&;") = ";
Entrada tmp$
A![ROW&,COL&]=val(tmp$)
A1![ROW&,COL&] = A![ROW&,COL&]
EndWhile
EndWhile
g870:
ENDPROC
Proc p900' SUBROUTINE VECTOR INPUT
Imprimir
WhileLoop n&:row&=&Loop
Imprimir " B(";ROW&;") = ";:Entrada tmp$:B![ROW&]=Val(tmp$)
EndWhile
ENDPROC
Proc p1000' SUBROUTINE FACTOR
declarar skip&
DET!=1
Whileloop n&:j&=&Loop
ROW&[J&]=J&
EndWhile
WHILELOOP n&-1:p&=&Loop
WhileLoop p&+1,n&:k&=&Loop
If Abs(A![ROW&[K&],P&]) > Abs(A![ROW&[P&],P&])
Goto "g1080"
Más
Goto "g1120"
EndIf
g1080:
T&=ROW&[P&]
ROW&[P&]=ROW&[K&]
ROW&[K&]=T&
DET!= -1*DET!
g1120:
EndWhile
DET!=DET!*A![ROW&[P&],P&]
Case DET!=0:skip&=1:BREAK'Goto "g1260"
WhileLoop p&+1,n&:k&=&Loop
ROWK&=ROW&[K&]
ROWP&=ROW&[P&]
A![ROWK&,P&] = A![ROWK&,P&] / A![ROWP&,P&]
Mientras que p&+1,n&:c&=&Loop
A![ROWK&,C&] = A![ROWK&,C&] - A![ROWK&,P&] * A![ROWP&,C&]
EndWhile
EndWhile
ENDWHILE
casenot skip&:DET!=DET!*A![ROW&[N&],N&]
g1260:
ENDPROC
Proc p1500' SUBROUTINE SOLVE
Whileloop n&:k&=&Loop
Case A![ROW&[K&],K&]=0:Goto "g1720"
EndWhile
X![1]=B![ROW&[1]]
WhileLoop 2,N&:K&=&Loop
SUM!=0
ROWK&=ROW&[K&]
WhileLoop k&-1:c&=&Loop
SUM!=SUM!+A![ROWK&,C&]*X![C&]
EndWhile
X![K&]=B![ROWK&]-SUM!
EndWhile
X![N&]=X![N&] / A![ROW&[N&],N&]
WhileLoop n&-1,1,-1:k&=&Loop
SUM!=0
ROWK&=ROW&[K&]
WhileLoop k&+1,n&,1:C&=&Loop
SUM!=SUM!+A![ROWK&,C&]*X![C&]
EndWhile
X![K&]=(X![K&]-SUM!)/A![ROWK&,K&]
EndWhile
g1720:
ENDPROC
Proc p2000' SUBROUTINE MATRIX PRINT
WhileLoop n&:row&=&Loop
Imprimir
WhileLoop n&:col&=&Loop
Imprimir A1![ROW&,COL&],
EndWhile
EndWhile
ENDPROC
Proc p2100' SUBROUTINE VECTOR PRINT
COL&=N&+1
Imprimir " B COEFFICIENT VECTOR ";"X SOLUTION VECTOR"
Imprimir
WhileLoop n&:Row&=&Loop
Imprimir " B(";ROW&;") = ";B![ROW&];" ";"X(";ROW&;") = ",X![ROW&]
EndWhile
ENDPROC
Proc p3000' SUBROUTINE RESULTS
CLS rnd(8^8)
Imprimir "\n COMPUTATION OF THE SOLUTION FOR THE LINEAR SYSTEM A*X = B."
Imprimir " THE TRIANGULAR FACTORIZATION L*U = P*A WAS CONSTRUCTED"
Imprimir " FIRST, THE SOLUTION Y TO L*Y = P*B WAS FOUND,"
Imprimir " SECOND, THE SOLUTION X TO U*X = Y WAS FOUND."
Imprimir " THE COEFFICIENT MATRIX A IS:"
Imprimir
p2000' call SUBROUTINE MATRIX PRINT
If DET! = 0
Goto "g3140"
Más
Goto "g3220"
EndIf
g3140:
Imprimir " THE MATRIX IS SINGULAR."
Imprimir " A ZERO PIVOT ELEMENT WAS ENCOUNTERED."
Imprimir " THE MATRIX DOES NOT HAVE TRIANGULAR FACTORIZATION."
Imprimir " THE METHOD DOES NOT APPLY."
Goto "g3250"
g3220:
Imprimir
p2100' call SUBROUTINE VECTOR PRINT
g3250:
Imprimir
Imprimir " THE DETERMINANT'S VALUE IS DET A = ",DET!
ENDPROC
|
|
|
| XProfan 11Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'... | 07.05.2021 ▲ |
|
|
|