English
Source / code snippets

Newton-Raphson vast speed: STEFFENSEN-Algorithmus

 

p.specht

How with of/ one here kubischen function To expect, supplying different Startwerte three different real Lösungs-Näherungen in the gefordertern Toleranzbereich. example: Newton-Raphson needed 44 Iterationen, Steffensen because of verbessertem Näherungsalgorithmus only seven! deference: Goto-Spagetticode old Style!
Window Title "STEFFENSEN-ALGORITHMUS"
'   accounts implizit The "Biegung" the Funktionskurve, nähert itself exponentiell.
'   ONLY FOR DEMONSTRATIONSZWECKE! No Gewähr! No warranties whatsoever!
' Original: 1987 John H Mathews, Californa State Univ.
Window Style 24:Font 2
Randomize:CLS Rnd(8^8)
Set("Decimals",15)
Declare DELTA!,EPSILON!,max&,ANS$,P0!,SMALL!,POLD!
Declare K&,COND&,P1!,P2!,p3!,P4!,DF0!,D1!,D2!,DP!,DF1!,Y3!,RELERR!
'*** HIER DIE FUNKTION SOWIE IHRE ABLEITUNG EINPROGRAMMIEREN:
'    FNF (X!) = X!*X!*X! - 3*X! + 2
Def FNF(1)  @!(1)*@!(1)*@!(1) - 3 * @!(1) + 2
'    FNF1(X!) = 3*X!*X! - 3
Def FNF1(1)  3*@!(1)*@!(1) - 3
'***********************************************************
Goto "G52"'skip print subroutine
s30:
' DIE FUNKTION IN KLARTEXT AUSGEBEN:
REM SUBROUTINE PRINT FUNCTION
PRINT "         F(X)  =  X^3 - 3*X + 2  = 0            "
Return
'***********************************************************
G52:
Goto "G100"
G100:
REM PROGRAM STEFFENS
DELTA!  =Val("1E-16")'Relative Fehlergrenze the Parameters
EPSILON!=Val("1E-16")'Ansolute Funktionswert-tolerance
MAX&=99'Maximale amount on Iterationen
G140:
Gosub "S300": REM SUBROUTINE INPUTS
GOSUB "S400": REM SUBROUTINE STEFFENSEN
GOSUB "S1000":REM SUBROUTINE RESULTS
PRINT
Print
PRINT " ANDEREN STARTWERT PROBIEREN <j/n>? ";
Input ANS$
Casenote (ANS$="N") Or (ANS$="n"):GOTO "G140"
GOTO "G5000"
s300:
REM SUBROUTINE INPUTS
CLS Rnd(8^8)
PRINT
PRINT " STEFFENSEN's BESCHLEUNIGUNG DES NEWTON-RAPHSON-ALGORITHMUS "
PRINT "   ZUR NULLSTELLENSUCHE IN EINER (NICHTLINEAREN) FUNKTION   "
PRINT
Gosub "S30"' ZU SUBROUTINE PRINT FUNCTION
PRINT
PRINT " it'll one anfänglicher Startwert P0 needed:"
PRINT " Gewünschter Startwert P0 = ";
Input P0!
PRINT
RETURN
s400:
REM SUBROUTINE STEFFENSEN
SMALL!=Val("1E-20")
POLD!=P0!
K&=0
COND&=0
P3!=P0!
P2!=P0!+1
P1!=P0!+2

WHILE (K& < MAX&) And (COND& = 0)

    P0!=P3!
    DF0!=FNF1(P0!)

    If DF0!<>0:Goto "G520"

        Else:Goto "G540"

    EndIf

    G520:
    P1!=P0! - FNF(P0!)/DF0!' Newton-Raphson-step
    Goto "G590"
    G540:
    REM ELSE
    COND&=1
    DP!=P3!-P2!
    P3!=P0!
    Goto "G860"
    G590:
    REM ENDIF
    DF1!=FNF1(P1!)

    If  DF1! <>0:Goto "G620"

        Else:Goto "G640"

    EndIf

    G620:
    P2!=P1! - FNF(P1!)/DF1!
    Goto "G690"
    G640:
    REM ELSE
    COND&=1
    DP!=P1!-P0!
    P3!=P1!
    Goto "G860"
    G690:
    REM ENDIF
    D1!=(P1!-P0!)*(P1!-P0!)
    D2!=P2!-2*P1!+P0!

    IF D2!=0:Goto "G730"

        Else:Goto "G770"

    EndIf

    G730:
    COND&=1
    DP!=P2!-P1!
    P3!=P2!
    GOTO "G800"
    G770:
    REM ELSE
    P3!=P0!-D1!/D2!
    DP!=P3!-P2!
    G800:
    REM ENDIF
    Y3!=FNF(P3!)
    RELERR!=Abs(DP!)/(Abs(P3!)+SMALL!)
    Case RELERR! < DELTA!:  COND&=2
    Case  Abs(Y3!) < EPSILON! : COND&=3
    Case  (RELERR!  < DELTA!) And (Abs(Y3!) < EPSILON!) : COND&=4
    G860:
    REM WEITER
    K&=K&+1

ENDWHILE

P0!=POLD!
RETURN
s1000:
REM SUBROUTINE RESULTS
CLS Rnd(8^8)
PRINT
PRINT " STEFFENSEN's BESCHLEUNIGUNG DES NEWTON-RAPHSON-ALGORITHMUS "
PRINT "   ZUR NULLSTELLENSUCHE IN EINER (NICHTLINEAREN) FUNKTION   "
PRINT
Gosub "S30"'PRINT-SUBROUTINE
PRINT
PRINT " The Startwert was P0 =",P0!
PRINT
PRINT " After "+Trim $(Str $(K&))+" Iterationen Virtually-Nullwert found with:"
Print : Print
Print "    P =",P3!
Print : Print
PRINT "  DP  =",ABS(DP!)," is its relative accuracy."
PRINT
Print "  F(";Trim $(Str $(P3!));") =",FNF(P3!)
PRINT
Case FNF(P3!)=0  : PRINT "  calculated function yielded GENAU NULL! "

If COND&=0:Goto "G1200"

    Else:Goto "G1240"

EndIf

PRINT "  The Konvergenz the Verfahrens is zweifelhaft. Begründung:"
PRINT
G1220:
PRINT "  Maximale Iterationszahl overstepped!"
Goto "G1400"
G1240:
REM ELSEIF

If COND&=1:Goto "G1260"

    Else:Goto "G1280"

EndIf

G1260:
PRINT "  Verfahrenskonvergenz zweifelhaft, there Division through zero."
Goto "G1400"
G1280:
REM ELSEIF

IF  COND&=2:Goto "G1300"

    Else:Goto "G1320"

EndIf

G1300:
PRINT "  Solution inside the programmierten Toleranzen."
Goto "G1400"
G1320:
REM ELSEIF

If COND&=3:Goto "G1340"

    Else:Goto "G1360"

EndIf

G1340:
PRINT "  Funktionswert F(P) inside the Toleranzgrenzen."
Goto "G1400"
G1360:
REM ELSEIF

If  COND&=4:Goto "G1380"

    Else: Goto "G1400"

EndIf

G1380:
PRINT "  The Parameter-worth  P and the Funktionswert F(P) "
PRINT "  lying both into programmierten Toleranzen.       "
G1400:
REM ENDIF
Return
G5000:
END
 
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
05/02/21  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

533 Views

Untitledvor 0 min.
funkheld01/01/22
Ernst07/21/21
Uwe ''Pascal'' Niemeier06/13/21
R.Schneider05/28/21
More...

Themeninformationen

this Topic has 1 subscriber:

p.specht (1x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie