Français
Source/ Codesnippets

Differentialgleichungen N-ter Ordre lösen: Størmer-Verlet Leapfrog-Methode

 

p.specht

Differentialgleichungen 2. bzw. n.ter Ordre lösen
=====================================
cela procéder, cela avec vollem Titel "Newton-Størmer-Verlet leapfrog method" heisst, findet sich dans presque allen Physik- et Game-Engines zur Berechnung qui Newtonschen Bewegungsgesetze. avec anderen Worten: Alles quoi explodiert et ensuite runterfällt wird avec cette deutlichen, mais doch pas trop zeitintensiven amélioration des einfachsten aller entsprechenden Algorithmen (Explizites Euler-procéder) berechnet. cela nachstehende Programme erlaubt une Beurteilung qui Realitätsnähe, weil aussi qui analytisch-exakte Solution qui devoir bekannt ist. Fünfstellige Genauigkeit reicht là wohl.

Es handelt sich um une Rückübersetzung de Fortran-90 pour XProfan-11, avec allen Tücken, daher: REINE DEMO OHNE JEDWEDE GEWÄHR!
Titre de la fenêtre "Anfangswertproblem einer Differentalgleichung 2. Ordre lösen pour Størmer-Verlet"
' ---------------------------------------------------------------------------------------------
' Aus Fortran90 pour XProfan-11 traduit 2014-08 de P. Specht, vienne (Österreich)
' aucun cependant geartete Gewähr! Verwendung sur alleinige péril de(s|r) Anwender(s|in)!
' source: https://jean-pierre.moreau.pagesperso-orange.fr/Cplus/stormer.txt
'**********************************************************************************************
'*  Differential equation y"=f(x,y,y') by  Størmer's method  *
' (erweiterbar sur allg. Verlet type, z.B. y'''[...]=f(x,y,y',y''[,y''',...])
'* --------------------------------------------------------- *
'* SAMPLE RUN (BEISPIEL)                                     *
'* Löse  y" = 8*y*y / (1+2*x) à partir de x=0 to x=1                *

proc G :parameters x!,y!,z!'= x, y, y'

    return 8*sqr(y!)/(1+2*x!)

endproc

proc F :parameters x!,y!,z!'= x, y, y'

    return z!

endproc

'* with initial conditions: x(0)=0, y(0)=1 and y'(0)=-2      *
Déclarer x![4],y![4],z![4],h!' Initial conditions:
x![1]= 0
y![1]= 1
z![1]=-2' dy/dt
h!=0.01' Step
'*  Compare to exact solution   y = 1/(1+2*x)                *

Proc Fx :parameters x!' Exact Solution:

    return 1/(1+2*x!)

endproc

'* --------------------------------------------------------- *
'*   Differential equation y"=f(x,y,y') by Stormer's method  *
'* --------------------------------------------------------- *
'*        X           Y           Y exact         Error      *
'*     0.000       1.000000       1.000000     0.0000000000  *
'*     0.010       0.980392       0.980392     0.0000000001  *
'*     0.020       0.961538       0.961538     0.0000000295  *
'*     0.030       0.943396       0.943396     0.0000000457  *
'*     0.040       0.925926       0.925926     0.0000000974  *
'*     0.050       0.909091       0.909091     0.0000001285  *
'*     ...         ...            ...          ...           *
'*     0.950       0.344866       0.344828     0.0000381695  *
'*     0.960       0.342505       0.342466     0.0000388874  *
'*     0.970       0.340176       0.340136     0.0000396196  *
'*     0.980       0.337878       0.337838     0.0000403406  *
'*     0.990       0.335612       0.335570     0.0000410721  *
'*     1.000       0.333375       0.333333     0.0000418231  *
'*                                                           *
'*   F90 Release By J-P Moreau, Paris (www.jpmoreau.fr).     *
'*************************************************************
Fenêtre Style 24:font 2:set("decimals",16):Fenêtre 0,0-%maxx,%maxy-40
Déclarer c![4],a1!,a2!,a3!,yex!,k&,il! , x1!,y1!,z1!
a1!= 1.083333333333333333 : a2!=-2*(a1!-1) : a3!= a1!-1
clearclip
imprimer "\n------------------------------------------------------------------------------"
imprimer "       Differentialgleichung y''=f(x,y,y') avec Störmer's Methode lösen "
imprimer "------------------------------------------------------------------------------\n"
imprimer "         X                   Y                  Y exact                Error\n"
putclip " X | Y | Y_exact | Error \n"
yex!=Fx(x![1]):imprimer tab(2);x![1],tab(22);y![1],tab(42);yex!,tab(62);er!
putclip str$(x![1])+"|"+str$(y![1])+"|"+str$(yex!)+"|"+str$(il!)+"\n"
' Runge-Kutta for first 2 steps:

whileloop 1,2:k&=&Boucle

    RK4D2 x![k&],y![k&],z![k&],h!
    x![k&+1]=x1!
    y![k&+1]=y1!
    z![k&+1]=z1!
    yex!=Fx(x![k&+1])
    il!=abs(yex!-y![k&+1])
    imprimer tab(2);x![k&+1],tab(22);y![k&+1],tab(42);yex!,tab(62);er!
    putclip str$(x![k&+1])+"|"+str$(y![k&+1])+"|"+str$(yex!)+"|"+str$(il!)+"\n"

endwhile

REPEAT'Main loop G10:

    whileloop 2,4:k&=&Boucle

        c![k&]=G( x![5-k&],y![5-k&],z![5-k&] )

    endwhile

    y![4]=2*y![3]-y![2]+sqr(h!)*(a1!*c![2]+a2!*c![3]+a3!*c![4])
    x![4]=x![3]+h!
    yex!=Fx(x![4])
    il!=abs(yex!-y![4])
    imprimer tab(2);x![4],tab(22);y![4],tab(42);yex!,tab(62);er!
    putclip str$(x![4])+"|"+str$(y![4])+"|"+str$(yex!)+"|"+str$(il!)+"\n"

    Whileloop 1,3:k&=&Boucle'pour prochain Schritt umkopieren:

        x![k&]=x![k&+1]
        y![k&]=y![k&+1]

    endwhile

    si %csrlin>40:waitinput 4000:cls

        imprimer "\n         X                   Y                  Y-exakt                Error\n"

    endif

UNTIL x![3]>1'end x value = 1

imprimer "\n EOF"
Imprimer " Resultate dans Zwischenablage!"
Waitinput
FIN

PROC RK4D2 :parameters x!,y!,z!,h!',x1!,y1!,z1!

    declare c1!,d1!,c2!,d2!,c3!,d3!,c4!,d4!
    c1!=F(x!,y!,z!)
    d1!=G(x!,y!,z!)
    c2!=F(x!+h!/2, y!+h!/2*c1!, z!+h!/2*d1!)
    d2!=G(x!+h!/2, y!+h!/2*c1!, z!+h!/2*d1!)
    c3!=F(x!+h!/2, y!+h!/2*c2!, z!+h!/2*d2!)
    d3!=G(x!+h!/2, y!+h!/2*c2!, z!+h!/2*d2!)
    c4!=F(x!+h!,   y!+h!*c3!,   z!+h!*d3!  )
    d4!=G(x!+h!,   y!+h!*c3!,   z!+h!*d3!  )
    x1!=x!+h!
    y1!=y!+h!*(c1!+2*c2!+2*c3!+c4!)/6
    z1!=z!+h!*(d1!+2*d2!+2*d3!+d4!)/6

endproc

PROGEND
'{=============================================================================================
'    Stormer, aka Newton-Størmer-Verlet leapfrog method
' =============================================================================================
' Namensgebung: qui Algorithmus selbst allez zurück sur Delambre (1791), oftmals wiederentdeckt,
' u.a. 1907 par Carl Størmer, 1909 par Cowell et Cromlin, 1967 populär par Loup Verlet.
' Verbessert qui explizite Euler-Methode sans allzu hohen Mehraufwand. souvent dans Physik-Engines
' pour trouver. Details siehe https://en.wikipedia.org/wiki/Verlet_integration
' =============================================================================================
' Methode STORMER (aka Newton-Störmer-Verlet-leapfrog method):
' löst Y"=f(x,y,y') avec gegebenen Anfangsbedingungen
' ----------------------------------------------------------------------------------
' une Differentialgleichung 2. Ordre (Y") peux ersetzt volonté par un
' Differentialgleichungs-SYSTEM bestehend aus 2 Gleichungen 1. Ordre!
' si alors y"=f(x,y,y') gegeben ist avec y(a=Anfang) et y'(a=Anfang), ensuite peux on
' cet Formel par Substitution u = y' umformen trop:
'
'                    | u'=f(x,y,u)
'                    | y'=u
'                    | avec den neuen Anfangsbedingungen y(a), u(a)
'
' commencer wir qui Betrachtung avec celui-là speziellen forme qui Taylor-Entwicklung,
' chez qui qui reste comme Integral dargestellt wird (Wiki: Taylorentwicklung)
'                                       x+h
'           y(x+h) = y(x) + h * y'(x) + INTEGRAL (x+h-t)*y"(t).dt
'                                        x
' par Verbringung qui Nichtintegral-Terme sur qui linke page et Aufspaltung
' des 'Restfehler-Integrals' dans deux Teile peux cet forme aussi suivant-
' maßen dargestellt volonté:
'                                        x+h              x-h
'           y(x+h) - 2y(x) + y(x-h) = INTEGRAL ...  +  INTEGRAL ...
'                                         x                x
' Pour cela zweite Integral wird qui Variable x eh bien substituiert par:  u = 2*x-t
' ensuite gilt sur Grund qui Kettenregel:
'           x-h                              x+h
'         INTEGRAL (x-h-t) * y"(t).dt = - INTEGRAL (x+h-u)*y"(u).du
'            x                                x
' et qui Ableitung .du rück-substituiert (trop .-dt) liefert ensuite:
'                                    x+h
'           du=-dt ==>           = INTEGRAL (x+h-t)*y"(2x-t).dt
'                                     x
' Somit peux on écrivons:              x+h
'           y(x+h) - 2*y(x) + y(x-h) = INTEGRAL (x+h-t)*[y"(t)+y"(2x-t)].dt
'                                         x
' eh bien verwenden wir sous Hinweis, qui oui y"(x)=f(x,y,y') gilt, folgenden Ausdruck
' comme Interpolationspolynom:
'                             x_n+1
'     y_n+1 - y_n + y_n-1 = INTEGRAL (x_n+1 - t)*[P(t)+P(2*x_n - 1)].dt  = ...
'                              x_n
'               x_n+1
'    ...= h^2*INTEGRAL (x_n+1 -t)*[O_00*Div(f_n)+O_11*Div(f_n)+O_22*Div(f_n)].dt ,
'                x_n
'                         1           |(-s) (m)|
' wobei O_mm  = -1^m * INTEGRAL (1-s)*|    +   | .ds
'                         0           |( m) (s)|
'                                               (vgl. aussi 'Adams-Bashford-Methode')
' Letzteres bringt uns schließlich trop STORMER's Formeln:
' ==================================================================================
' Explizit formuliert:  y_n+1 -2*y_n + y_n-1 = h^2/12 * [13 * f_n - 2*f_n-1 + f_n-2]
' cela interessierende   y_n+1 = h^2/12 * [13 * f_n - 2*f_n-1 + f_n-2]+ 2*y_n - y_n-1
' (f_n+1 muss pas bekannt son: Prognoserechnung chez aktuell ergänzten Zeitreihen)
' ----------------------------------------------------------------------------------
' ou bien implizit:        y_n+1 -2*y_n + y_n-1 = h^2/12 * [f_n+1 + 10 * f_n + f_n-1 ]
'}==================================================================================
 
XProfan 11
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
14.05.2021  
 



Zum Quelltext


Topictitle, max. 100 marque.
 

Systemprofile:

ne...aucune Systemprofil angelegt. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

s'il te plaît s'inscrire um une Beitrag trop verfassen.
 

Options du sujet

1.703 Views

Untitledvor 0 min.
H.Brill07.12.2023
p.specht01.07.2022
E.T.20.11.2021
Manfred Barei19.11.2021
plus...

Themeninformationen

cet Thema hat 1 participant:

p.specht (1x)


Admins  |  AGB  |  Applications  |  Auteurs  |  Chat  |  protection des données  |  Télécharger  |  Entrance  |  Aider  |  Merchantportal  |  Empreinte  |  Mart  |  Interfaces  |  SDK  |  Services  |  Jeux  |  cherche  |  Support

un projet aller XProfaner, qui il y a!


Mon XProfan
Privé Nouvelles
Eigenes Ablageforum
Sujets-La liste de voeux
Eigene Posts
Eigene Sujets
Zwischenablage
Annuler
 Deutsch English Français Español Italia
Traductions

protection des données


Wir verwenden Cookies seulement comme Session-Cookies à cause de qui technischen Notwendigkeit et chez uns gibt es aucun Cookies de Drittanbietern.

si du ici sur unsere Webseite klickst ou bien navigierst, stimmst du unserer Erfassung de Informationen dans unseren Cookies sur XProfan.Net trop.

Weitere Informationen trop unseren Cookies et en supplément, comment du qui Kontrolle par-dessus behältst, findest du dans unserer nachfolgenden Datenschutzerklärung.


d'accordDatenschutzerklärung
je voudrais keinen Cookie