| |
|
|
p.specht
| in the july 2011 of VisualBasic to Profan11.2a transfer. demonstration without each Gewähr!
'Var Koeff$="1,10"
'Var Koeff$="10,0,-1000"
'Var Koeff$="1,-10,0,100,0,10,0,1,0,-1000"
Var Koeff$="10,0,-20.2,1.8,-40,300,-1,0"
Window Title "Nullstellen of Polynomen - Bairstow-Verfahren"
' fountain: https://www.rhirte.de/vb/home2.htm
' Umsetzung the VB-Program of Prof.em. Dr.Rolf Hirte, technical college Wildau
' to XProfan 11.2a; only to demonstration gedacht; No warranty! Demoware only!
' accompanying text: The Solution of Polynomausdrücken (Nullstellensuche) becomes uncomfortably, if the
' Polynom about of Grade 5 or z,B. 25 is. Bairstow verfährt thereby folgendermaßen:
' it split in a Iteration ongoing The quadratischen factors ex, The then in known point
' (set of Vieta) resolved go - the such a long time, To the Restpolynom of Grade 0 or 1 is.
' The users must LEDIGLICH each Koeffizienten the on Normalform "Polynom = 0" brought Polynoms
' in fallender Potenz provide (Text in starker Anlehnung on The named fountain).
'
' WIR HIER pack The Koeffizienten as well as the Absolutglied to fallendem Exponenten in a
' comma-separierten String, z.B. Var Koeff$="10,20,-2.2,1.8,-40,300,1.1111111,0", see 1. row.
' thereafter GEHTS go:
Cls
Font 2
AppendMenuBar 253,"Run Bairstow"
AppendMenuBar 252,"Finish"
print
Declare Grad&,A$[],A![],W!
A$[]=Explode(Koeff$,","):Grad&=SizeOf(A $[])-1
SetSize A![],Grad&
WhileLoop 0,Grad&
A![&Loop]=val(A $[Grad&-&Loop])
EndWhile
WhileLoop Grad&,0,-1
Set("NumWidth",1) :set("Decimals",0)
if &Loop<Grad&:print " +";:else:print " ";:endif
Print "X^";&Loop,
Set("NumWidth",26):set("Decimals",15):Print " time ";A![&Loop]
EndWhile
Print:Print " for Berechnungsstart Please Button pressing!"
WaitInput
CLS
Set("NumWidth",1) :set("Decimals",0)
Print "Das given Polynom of strain ";Grad&;" has following Nullstellen:":Print
Bairstow(A![])
WaitInput
End'Main
Proc Bairstow
Parameters A![]
Var Grad& = SizeOf(A![])-1
Declare i&,R!,P!,P1!,Q!,Q1!,Ce!,s!,t!
Declare B![Grad&],C![Grad&]
set("NumWidth",20):set("Decimals",15)
While Grad& > 2
R! = 0
P1! = 1
Q1! = -1
B![Grad&] = A![Grad&]
C![Grad&] = A![Grad&]
Repeat
P! = P1!
Q! = Q1!
B![Grad&-1] = B![Grad&] * P! + A![Grad& - 1]
C![Grad&-1] = B![Grad&-1] + B![Grad&] * P!
Whileloop Grad& - 2 , 0 , -1 : i& = &Loop'For
B![i&] = B![i& + 2] * Q! + B![i& + 1] * P! + A![i&]
C![i&] = C![i& + 2] * Q! + C![i& + 1] * P! + B![i&]
EndWhile' Next
Ce! = C![2] * C![2] - C![1] * C![3]
case Ce! = 0 : Print " others Startwerte necessary!"
P1! = P! - (B![1] * C![2] - B![0] * C![3]) / Ce!
Q1! = Q! - (B![0] * C![2] - B![1] * C![1]) / Ce!
R! = R! + 1
If R! > 4000
Print:Print:Print " Sorry, to 4000 rounds no (further) Konvergenz!"
WaitInput
End
EndIf
Until Abs(B![0]) + Abs(B![1]) < 10^-12' inside loop
' Nullstelle the quad. Faktors
s! = P1! / 2
t! = P1!*P1! + 4 * Q1!
If t! < 0
Print s!;" + ";0.5 * Sqrt(-t!);"*i "; : comment
Print s!;" - ";0.5 * Sqrt(-t!);"*i "; : comment
Else
Print s! + 0.5 * Sqrt(t!)
Print s! - 0.5 * Sqrt(t!)
EndIf
whileloop 2,Grad&
i& = &Loop
A![i& - 2] = B![i&]
endwhile
Grad& = Grad& - 2
EndWhile' Outer Loop
If Grad& = 1
Print -A![0]/A![1]
Else
s! = -0.5 * A![1] / A![2]
t! = A![1] * A![1] - 4 * A![2] * A![0]
If t! < 0
Print s!;" + ";0.5 * Sqrt(-t!) / A![2];"*i "; : comment
Print s!;" - ";0.5 * Sqrt(-t!) / A![2];"*i "; : comment
Else
Print s! + 0.5 * Sqrt(t!) / A![2]
Print s! - 0.5 * Sqrt(t!) / A![2]
EndIf
EndIf
ENDPROC
Proc comment
if nearly(s!,0,9)
print "(Imaginär)"
else
print "(Komplex)"
endif
endproc
|
|
|
| Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'... | 04/18/21 ▲ |
|
|
|